mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-15 17:31:31 +02:00
REST API support for DHCP Relay
Change-Id: Icfefebd15ff43718493e5223254b23ec02ee0bab
This commit is contained in:
parent
db14847c2d
commit
b710909185
@ -1,30 +1,8 @@
|
|||||||
COMPILE_DEPS = [
|
|
||||||
'//lib:CORE_DEPS',
|
|
||||||
'//lib:JACKSON',
|
|
||||||
'//lib:KRYO',
|
|
||||||
'//lib:org.apache.karaf.shell.console',
|
|
||||||
'//cli:onos-cli',
|
|
||||||
'//core/store/serializers:onos-core-serializers',
|
|
||||||
'//apps/route-service/api:onos-apps-route-service-api',
|
|
||||||
'//apps/routing/fpm/api:onos-apps-routing-fpm-api',
|
|
||||||
]
|
|
||||||
|
|
||||||
TEST_DEPS = [
|
|
||||||
'//lib:TEST',
|
|
||||||
'//apps/route-service/api:onos-apps-route-service-api-tests',
|
|
||||||
'//core/api:onos-api-tests',
|
|
||||||
]
|
|
||||||
|
|
||||||
BUNDLES = [
|
BUNDLES = [
|
||||||
'//apps/dhcprelay:onos-apps-dhcprelay',
|
'//apps/dhcprelay/web:onos-apps-dhcprelay-web',
|
||||||
'//apps/routing/fpm/api:onos-apps-routing-fpm-api',
|
'//apps/dhcprelay/app:onos-apps-dhcprelay-app',
|
||||||
]
|
]
|
||||||
|
|
||||||
osgi_jar_with_tests (
|
|
||||||
deps = COMPILE_DEPS,
|
|
||||||
test_deps = TEST_DEPS,
|
|
||||||
)
|
|
||||||
|
|
||||||
onos_app (
|
onos_app (
|
||||||
app_name = 'org.onosproject.dhcprelay',
|
app_name = 'org.onosproject.dhcprelay',
|
||||||
title = 'DHCP Relay Agent',
|
title = 'DHCP Relay Agent',
|
||||||
|
@ -1,24 +1,8 @@
|
|||||||
COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [
|
|
||||||
"//core/store/serializers:onos-core-serializers",
|
|
||||||
"//apps/route-service/api:onos-apps-route-service-api",
|
|
||||||
"//apps/routing/fpm/api:onos-apps-routing-fpm-api",
|
|
||||||
]
|
|
||||||
|
|
||||||
TEST_DEPS = TEST + [
|
|
||||||
"//apps/route-service/api:onos-apps-route-service-api-tests",
|
|
||||||
"//core/api:onos-api-tests",
|
|
||||||
]
|
|
||||||
|
|
||||||
BUNDLES = [
|
BUNDLES = [
|
||||||
"//apps/dhcprelay:onos-apps-dhcprelay",
|
"//apps/dhcprelay/web:onos-apps-dhcprelay-web",
|
||||||
"//apps/routing/fpm/api:onos-apps-routing-fpm-api",
|
"//apps/dhcprelay/app:onos-apps-dhcprelay-app",
|
||||||
]
|
]
|
||||||
|
|
||||||
osgi_jar_with_tests(
|
|
||||||
test_deps = TEST_DEPS,
|
|
||||||
deps = COMPILE_DEPS,
|
|
||||||
)
|
|
||||||
|
|
||||||
onos_app(
|
onos_app(
|
||||||
app_name = "org.onosproject.dhcprelay",
|
app_name = "org.onosproject.dhcprelay",
|
||||||
category = "Utility",
|
category = "Utility",
|
||||||
|
21
apps/dhcprelay/app/BUCK
Normal file
21
apps/dhcprelay/app/BUCK
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
COMPILE_DEPS = [
|
||||||
|
'//lib:CORE_DEPS',
|
||||||
|
'//lib:JACKSON',
|
||||||
|
'//lib:KRYO',
|
||||||
|
'//lib:org.apache.karaf.shell.console',
|
||||||
|
'//cli:onos-cli',
|
||||||
|
'//core/store/serializers:onos-core-serializers',
|
||||||
|
'//apps/route-service/api:onos-apps-route-service-api',
|
||||||
|
'//apps/routing/fpm/api:onos-apps-routing-fpm-api',
|
||||||
|
]
|
||||||
|
|
||||||
|
TEST_DEPS = [
|
||||||
|
'//lib:TEST',
|
||||||
|
'//apps/route-service/api:onos-apps-route-service-api-tests',
|
||||||
|
'//core/api:onos-api-tests',
|
||||||
|
]
|
||||||
|
|
||||||
|
osgi_jar_with_tests (
|
||||||
|
deps = COMPILE_DEPS,
|
||||||
|
test_deps = TEST_DEPS,
|
||||||
|
)
|
15
apps/dhcprelay/app/BUILD
Normal file
15
apps/dhcprelay/app/BUILD
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [
|
||||||
|
"//core/store/serializers:onos-core-serializers",
|
||||||
|
"//apps/route-service/api:onos-apps-route-service-api",
|
||||||
|
"//apps/routing/fpm/api:onos-apps-routing-fpm-api",
|
||||||
|
]
|
||||||
|
|
||||||
|
TEST_DEPS = TEST + [
|
||||||
|
"//apps/route-service/api:onos-apps-route-service-api-tests",
|
||||||
|
"//core/api:onos-api-tests",
|
||||||
|
]
|
||||||
|
|
||||||
|
osgi_jar_with_tests(
|
||||||
|
test_deps = TEST_DEPS,
|
||||||
|
deps = COMPILE_DEPS,
|
||||||
|
)
|
23
apps/dhcprelay/web/BUCK
Normal file
23
apps/dhcprelay/web/BUCK
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
COMPILE_DEPS = [
|
||||||
|
'//lib:CORE_DEPS',
|
||||||
|
'//lib:JACKSON',
|
||||||
|
'//lib:KRYO',
|
||||||
|
'//lib:org.apache.karaf.shell.console',
|
||||||
|
'//cli:onos-cli',
|
||||||
|
'//utils/rest:onlab-rest',
|
||||||
|
'//lib:javax.ws.rs-api',
|
||||||
|
'//lib:jersey-server',
|
||||||
|
'//core/store/serializers:onos-core-serializers',
|
||||||
|
'//apps/route-service/api:onos-apps-route-service-api',
|
||||||
|
'//apps/dhcprelay/app:onos-apps-dhcprelay-app',
|
||||||
|
'//apps/routing/fpm/api:onos-apps-routing-fpm-api',
|
||||||
|
]
|
||||||
|
|
||||||
|
osgi_jar (
|
||||||
|
deps = COMPILE_DEPS,
|
||||||
|
web_context = '/onos/v1/dhcprelay',
|
||||||
|
api_title = 'DHCPRelay App',
|
||||||
|
api_version = '1.0',
|
||||||
|
api_description = 'REST API for DHCPRelay',
|
||||||
|
api_package = 'org.onosproject.dhcprelay.rest',
|
||||||
|
)
|
16
apps/dhcprelay/web/BUILD
Normal file
16
apps/dhcprelay/web/BUILD
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
COMPILE_DEPS = CORE_DEPS + KRYO + JACKSON + REST + CLI + [
|
||||||
|
"@jersey_server//jar",
|
||||||
|
"//core/store/serializers:onos-core-serializers",
|
||||||
|
"//apps/route-service/api:onos-apps-route-service-api",
|
||||||
|
"//apps/dhcprelay/app:onos-apps-dhcprelay-app",
|
||||||
|
"//apps/routing/fpm/api:onos-apps-routing-fpm-api",
|
||||||
|
]
|
||||||
|
|
||||||
|
osgi_jar(
|
||||||
|
api_description = "REST API for DHCPRelay",
|
||||||
|
api_package = "org.onosproject.dhcprelay.rest",
|
||||||
|
api_title = "REST API for DHCPRelay Agent Application",
|
||||||
|
api_version = "1.0",
|
||||||
|
web_context = "/onos/v1/dhcprelay",
|
||||||
|
deps = COMPILE_DEPS,
|
||||||
|
)
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.dhcprelay.rest;
|
||||||
|
|
||||||
|
import org.onlab.rest.AbstractWebApplication;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DHCP Relay Web application.
|
||||||
|
*/
|
||||||
|
public class DhcpRelayWebApplication extends AbstractWebApplication {
|
||||||
|
@Override
|
||||||
|
public Set<Class<?>> getClasses() {
|
||||||
|
return getClasses(DhcpRelayWebResource.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.dhcprelay.rest;
|
||||||
|
|
||||||
|
import org.onlab.packet.IpAddress;
|
||||||
|
import org.onlab.packet.IpPrefix;
|
||||||
|
import org.onosproject.dhcprelay.api.DhcpRelayService;
|
||||||
|
import org.onosproject.rest.AbstractWebResource;
|
||||||
|
import org.onosproject.routeservice.Route;
|
||||||
|
import org.onosproject.routeservice.RouteStore;
|
||||||
|
import org.onosproject.routing.fpm.api.FpmRecord;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DHCP Relay agent REST API.
|
||||||
|
*/
|
||||||
|
@Path("fpm-delete")
|
||||||
|
public class DhcpRelayWebResource extends AbstractWebResource {
|
||||||
|
private static final Logger LOG = getLogger(DhcpRelayWebResource.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the fpm route from fpm record.
|
||||||
|
* Corresponding route from the route store
|
||||||
|
*
|
||||||
|
* @param prefix IpPrefix
|
||||||
|
* @return 204 NO CONTENT
|
||||||
|
* @throws IOException to signify bad request
|
||||||
|
*/
|
||||||
|
@DELETE
|
||||||
|
@Path("{prefix}")
|
||||||
|
public Response dhcpFpmDelete(@PathParam("prefix") String prefix) {
|
||||||
|
DhcpRelayService dhcpRelayService = get(DhcpRelayService.class);
|
||||||
|
RouteStore routeStore = get(RouteStore.class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// removes fpm route from fpm record
|
||||||
|
Optional<FpmRecord> fpmRecord = dhcpRelayService.removeFpmRecord(IpPrefix.valueOf(prefix));
|
||||||
|
if (fpmRecord.isPresent()) {
|
||||||
|
IpAddress nextHop = fpmRecord.get().nextHop();
|
||||||
|
Route route = new Route(Route.Source.DHCP, IpPrefix.valueOf(prefix), nextHop);
|
||||||
|
// removes DHCP route from route store
|
||||||
|
routeStore.removeRoute(route);
|
||||||
|
} else {
|
||||||
|
LOG.warn("fpmRecord is not present");
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
throw new IllegalArgumentException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DHCP Relay agent REST API.
|
||||||
|
*/
|
||||||
|
package org.onosproject.dhcprelay.rest;
|
57
apps/dhcprelay/web/src/main/webapp/WEB-INF/web.xml
Normal file
57
apps/dhcprelay/web/src/main/webapp/WEB-INF/web.xml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright 2018-present Open Networking Foundation
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
id="ONOS" version="2.5">
|
||||||
|
<display-name>DHCPRELAY REST API v1.0</display-name>
|
||||||
|
|
||||||
|
<security-constraint>
|
||||||
|
<web-resource-collection>
|
||||||
|
<web-resource-name>Secured</web-resource-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</web-resource-collection>
|
||||||
|
<auth-constraint>
|
||||||
|
<role-name>admin</role-name>
|
||||||
|
</auth-constraint>
|
||||||
|
</security-constraint>
|
||||||
|
|
||||||
|
<security-role>
|
||||||
|
<role-name>admin</role-name>
|
||||||
|
</security-role>
|
||||||
|
|
||||||
|
<login-config>
|
||||||
|
<auth-method>BASIC</auth-method>
|
||||||
|
<realm-name>karaf</realm-name>
|
||||||
|
</login-config>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>JAX-RS Service</servlet-name>
|
||||||
|
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
|
||||||
|
<init-param>
|
||||||
|
<param-name>javax.ws.rs.Application</param-name>
|
||||||
|
<param-value>org.onosproject.dhcprelay.rest.DhcpRelayWebApplication</param-value>
|
||||||
|
</init-param>
|
||||||
|
<load-on-startup>1</load-on-startup>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>JAX-RS Service</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
</web-app>
|
@ -288,7 +288,8 @@ APP_JARS = [
|
|||||||
"//apps/dhcp/app:onos-apps-dhcp-app",
|
"//apps/dhcp/app:onos-apps-dhcp-app",
|
||||||
"//apps/imr/api:onos-apps-imr-api",
|
"//apps/imr/api:onos-apps-imr-api",
|
||||||
"//apps/imr/app:onos-apps-imr-app",
|
"//apps/imr/app:onos-apps-imr-app",
|
||||||
"//apps/dhcprelay:onos-apps-dhcprelay",
|
"//apps/dhcprelay/app:onos-apps-dhcprelay-app",
|
||||||
|
"//apps/dhcprelay/web:onos-apps-dhcprelay-web",
|
||||||
"//apps/fwd:onos-apps-fwd",
|
"//apps/fwd:onos-apps-fwd",
|
||||||
"//apps/iptopology-api:onos-apps-iptopology-api",
|
"//apps/iptopology-api:onos-apps-iptopology-api",
|
||||||
"//apps/routing/common:onos-apps-routing-common",
|
"//apps/routing/common:onos-apps-routing-common",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user