<type>xml</type>
<classifier>config</classifier>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-northbound-route-networkmap-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-northbound-route-networkmap-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-northbound-route-networkmap-impl</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>config</classifier>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-service-model-base-features</artifactId>
+ <classifier>features</classifier>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-service-model-networkmap-features</artifactId>
+ <classifier>features</classifier>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
</project>
<repository>mvn:org.opendaylight.mdsal.model/features-mdsal-model/${mdsal.model.version}/xml/features</repository>
<repository>mvn:org.opendaylight.netconf/features-restconf/${restconf.version}/xml/features</repository>
<repository>mvn:org.opendaylight.dlux/features-dlux/${dlux.version}/xml/features</repository>
+
+ <repository>mvn:org.opendaylight.alto.core/alto-service-model-networkmap-features/${project.version}/xml/features</repository>
+
<feature name='odl-alto-northbound-api' version='${project.version}' description='OpenDaylight :: alto-northbound :: api'>
<feature version='${mdsal.model.version}'>odl-mdsal-models</feature>
<feature version="${restconf.version}">odl-restconf</feature>
<feature name='odl-alto-northbound-route-test' version='${project.version}' description='OpenDaylight :: ALTO :: Route Exmaple'>
<feature version='${project.version}'>odl-alto-northbound</feature>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-example/${project.version}</bundle>
- <configfile finalname="${configfile.directory}/alto-northbound-route-example.xml">mvn:org.opendaylight.alto.core/alto-northbound-route-example/${project.version}/xml/config</configfile>
+ <configfile finalname="${configfile.directory}/alto-northbound-route-example.xml">
+ mvn:org.opendaylight.alto.core/alto-northbound-route-example/${project.version}/xml/config
+ </configfile>
+
+ <feature version='${project.version}'>odl-alto-service-model-networkmap</feature>
+ <bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-api/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-impl/${project.version}</bundle>
+ <configfile finalname="${configfile.directory}/alto-northbound-route-networkmap.xml">
+ mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-impl/${project.version}/xml/config
+ </configfile>
</feature>
<feature name='odl-alto-northbound-rest' version='${project.version}' description='OpenDaylight :: alto-northbound :: REST'>
<feature version="${project.version}">odl-alto-northbound</feature>
</plugin>
</plugins>
</build>
-
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/alto-northbound.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/alto-northbound.git</developerConnection>
- <tag>HEAD</tag>
- <url>https://wiki.opendaylight.org/view/alto-northbound:Main</url>
- </scm>
</project>
@Override
public java.lang.AutoCloseable createInstance() {
getAltoNorthboundRouterDependency().addRoute("example", new AltoNorthboundRouteExample());
- System.out.println("haha");
return new AutoCloseable() {
@Override
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright © 2015 Yale University and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.alto.core</groupId>
+ <artifactId>alto-northbound-route-networkmap-api</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-service-model-networkmap-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlets</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-server</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-inet-types-2013-07-15</artifactId>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2015 Yale University and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.alto.core.northbound.route.networkmap;
+
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.Records;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.records.Record;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.records.RecordKey;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class AltoNbrNetworkmapUtils {
+
+ public static InstanceIdentifier<Record> getRecordIID(String path) {
+ RecordKey key = new RecordKey(new Uri(path));
+ return InstanceIdentifier.builder(Records.class).child(Record.class, key).build();
+ }
+}
+
--- /dev/null
+module alto-nbr-networkmap {
+ yang-version 1;
+
+ namespace "urn:opendaylight:alto:core:northbound:route:networkmap";
+
+ prefix "alto-nbr-networkmap";
+
+ import config { prefix config; revision-date 2013-04-05; }
+ import ietf-inet-types { prefix ietf-inet; revision-date 2013-07-15; }
+ import alto-model-networkmap { prefix networkmap-model; revision-date 2015-10-21; }
+
+ organization "Yale University";
+
+ contact "alto-dev@lists.opendaylight.org";
+
+ revision "2015-10-21" {
+ description "Initial revision of alto-northbound model";
+ }
+
+ container "records" {
+ list "record" {
+ key "path";
+
+ leaf "path" {
+ type ietf-inet:uri;
+ }
+
+ leaf "resource-iid" {
+ type instance-identifier;
+ }
+
+ list "address-type-mapping" {
+ key "address-type-string";
+
+ leaf "address-type-string" {
+ type string;
+ }
+
+ leaf "address-type" {
+ type identityref {
+ base "networkmap-model:address-type-base";
+ }
+ }
+ }
+ }
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2015 Yale University and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.alto.core</groupId>
+ <artifactId>alto-northbound-route-networkmap-impl</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-northbound-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-service-model-networkmap-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-northbound-route-networkmap-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>ietf-inet-types-2013-07-15</artifactId>
+ </dependency>
+
+ <!-- Testing Dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-json-org</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-base</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.module</groupId>
+ <artifactId>jackson-module-jaxb-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlets</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${bundle.plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>*,com.sun.jersey.spi.container.servlet, org.eclipse.jetty.servlets</Import-Package>
+ <Web-ContextPath>/alto</Web-ContextPath>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2015 Yale University and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<snapshot>
+ <required-capabilities>
+ <capability>urn:opendaylight:alto:core:northbound:route:networkmap:impl?module=alto-northbound-route-networkmap-impl&revision=2015-10-21</capability>
+ <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28</capability>
+ <capability>urn:opendaylight:alto:core:northbound?module=alto-northbound&revision=2015-10-21</capability>
+ </required-capabilities>
+ <configuration>
+
+ <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+ <module>
+ <type xmlns:prefix="urn:opendaylight:alto:core:northbound:route:networkmap:impl">prefix:alto-northbound-route-networkmap-impl</type>
+ <name>alto-northbound-route-networkmap</name>
+ <broker>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
+ <name>binding-osgi-broker</name>
+ </broker>
+ <alto-northbound-router>
+ <type xmlns:alto-northbound-router="urn:opendaylight:alto:core:northbound">alto-northbound-router:alto-northbound-router</type>
+ <name>alto-northbound-router</name>
+ </alto-northbound-router>
+ </module>
+ </modules>
+ </data>
+ </configuration>
+</snapshot>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata modelVersion="1.1.0">
+ <groupId>org.opendaylight.alto.core</groupId>
+ <artifactId>alto-northbound-impl</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <versioning>
+ <snapshot>
+ <localCopy>true</localCopy>
+ </snapshot>
+ <lastUpdated>20151105030453</lastUpdated>
+ <snapshotVersions>
+ <snapshotVersion>
+ <classifier>config</classifier>
+ <extension>xml</extension>
+ <value>0.2.0-SNAPSHOT</value>
+ <updated>20151105030453</updated>
+ </snapshotVersion>
+ </snapshotVersions>
+ </versioning>
+</metadata>
--- /dev/null
+/*
+ * Copyright (c) 2015 Yale University and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.alto.core.northbound.route.networkmap.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Future;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.google.common.base.Optional;
+
+import org.opendaylight.alto.core.northbound.api.AltoNorthboundRoute;
+import org.opendaylight.alto.core.northbound.api.AltoNorthboundRouter;
+
+import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285NetworkMap;
+import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285Endpoint.AddressGroup;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.Records;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.records.Record;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.records.RecordKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.records.record.AddressTypeMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.rev151021.records.record.AddressTypeMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.Resource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.ContextTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.resourcepool.rev150921.context.resource.ContextTagKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.types.rev150921.PidName;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AddressTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AltoModelNetworkmapService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.QueryInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.QueryInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.QueryOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.ResourceTypeNetworkmap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.alto.request.networkmap.request.NetworkmapRequestBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.alto.response.networkmap.response.NetworkmapResponse;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.networkmap.request.data.NetworkmapFilterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.networkmap.response.data.NetworkMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.networkmap.response.data.network.map.Partition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rfc7285.rev151021.Ipv4PrefixList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rfc7285.rev151021.Ipv6PrefixList;
+
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AltoNorthboundRouteNetworkmap implements BindingAwareProvider, AutoCloseable, AltoNorthboundRoute {
+ public static final String NETWORKMAP_ROUTE = "networkmap";
+
+ public static final String ALTO_NETWORKMAP_FILTER = "application/alto-networkmapfilter+json";
+ public static final String ALTO_NETWORKMAP = "application/alto-networkmap+json";
+
+ public static final String FIELD_PIDS = "pids";
+ public static final String FIELD_ADDR_TYPES = "address-types";
+
+ private ObjectMapper mapper = new ObjectMapper();
+ private static final Logger LOG = LoggerFactory.getLogger(AltoNorthboundRouteNetworkmap.class);
+ private static DataBroker m_dataBroker = null;
+ private AltoNorthboundRouter m_router = null;
+
+ private static AltoModelNetworkmapService mapService = null;
+ @Override
+ public void onSessionInitiated(ProviderContext session) {
+ m_dataBroker = session.getSALService(DataBroker.class);
+ if (m_dataBroker == null) {
+ LOG.error("Failed to init: data broker is null");
+ }
+ mapService = session.getRpcService(AltoModelNetworkmapService.class);
+ LOG.info("AltoNorthboundRouteNetworkmap initiated");
+ }
+
+ public void register(AltoNorthboundRouter router) {
+ m_router = router;
+ m_router.addRoute("networkmap", new AltoNorthboundRouteNetworkmap());
+ }
+
+ @Override
+ public void close() {
+ m_router.removeRoute("networkmap");
+ }
+
+ @Path("{path}")
+ @GET
+ @Produces({ALTO_NETWORKMAP, ALTO_ERROR})
+ public Response getFullMap(@PathParam("path") String path) throws JsonProcessingException {
+ QueryInput input = prepareDefaultInput(path);
+ Future<RpcResult<QueryOutput>> outputFuture = mapService.query(input);
+ QueryOutput output = null;
+ try {
+ output = outputFuture.get().getResult();
+ } catch (Exception e) {
+ LOG.warn("get output failed:" , e);
+ }
+ Response response = buildOutput(input, output);
+ if(response != null)
+ return response;
+ else
+ return Response.status(404).build();
+ }
+
+ @Path("{path}")
+ @POST
+ @Consumes({ALTO_NETWORKMAP_FILTER})
+ @Produces({ALTO_NETWORKMAP, ALTO_ERROR})
+ public Response getFilteredMap(@PathParam("path") String path, String filter) throws JsonProcessingException {
+ Response error;
+
+ List<String> pids = null;
+ List<String> addressTypes = null;
+
+ try {
+ JsonNode filterNode = mapper.readTree(filter);
+
+ JsonNode _pids = filterNode.get(FIELD_PIDS);
+
+ error = NetworkmapRouteChecker.checkMissing(_pids, FIELD_PIDS, filter);
+ if (error != null)
+ return error;
+
+ error = NetworkmapRouteChecker.checkList(_pids, FIELD_PIDS, filter);
+ if (error != null)
+ return error;
+
+ pids = arrayNode2List(FIELD_PIDS, (ArrayNode)_pids);
+
+ JsonNode _addressTypes = filterNode.get(FIELD_ADDR_TYPES);
+ error = NetworkmapRouteChecker.checkMissing(_addressTypes, FIELD_ADDR_TYPES, filter);
+ if (error == null) {
+ error = NetworkmapRouteChecker.checkList(_addressTypes, FIELD_ADDR_TYPES, filter);
+
+ if (error != null)
+ return error;
+
+ addressTypes = arrayNode2List(FIELD_ADDR_TYPES, (ArrayNode)_addressTypes);
+ }
+ } catch (JsonProcessingException e) {
+ throw e;
+ } catch (Exception e) {
+ return Response.status(500).build();
+ }
+
+ //TODO
+ QueryInput input = prepareInput(path, pids, addressTypes);
+ Future<RpcResult<QueryOutput>> outputFuture = mapService.query(input);
+ QueryOutput output = null;
+ try {
+ output = outputFuture.get().getResult();
+ } catch (Exception e) {
+ LOG.warn("get output failed:" , e);
+ }
+ Response response = buildOutput(input, output);
+ if(response != null)
+ return response;
+ else
+ return Response.status(404).build();
+ }
+
+ protected List<String> arrayNode2List(String field, ArrayNode node) {
+ HashSet<String> retval = new HashSet<String>();
+
+ for (Iterator<JsonNode> itr = node.elements(); itr.hasNext(); ) {
+ JsonNode data = itr.next();
+
+ retval.add(data.asText());
+ }
+ return new LinkedList<String>(retval);
+ }
+
+ protected QueryInput prepareDefaultInput(String rid) {
+ /*
+ * Set pids as empty so all PID should be returned.
+ *
+ * Set address-types as missing so all address types should be returned.
+ *
+ * See https://tools.ietf.org/html/rfc7285#section-11.3.1.3
+ *
+ * */
+ return prepareInput(rid, new LinkedList<String>(), null);
+ }
+
+ protected QueryInput prepareInput(String path, List<String> pids, List<String> addressTypes) {
+ //TODO
+ QueryInputBuilder queryInputBuilder = new QueryInputBuilder();
+
+ ReadOnlyTransaction rtx = m_dataBroker.newReadOnlyTransaction();
+ InstanceIdentifier<ContextTag> ctagIID = getResourceByPath(path, rtx);
+ if(ctagIID == null){
+ return null;
+ }
+ NetworkmapRequestBuilder networkmapRequestBuilder = new NetworkmapRequestBuilder();
+ NetworkmapFilterBuilder networkmapFilterBuilder = new NetworkmapFilterBuilder();
+
+ List<PidName> pidNames = new LinkedList<PidName>();
+ for (String pid:pids){
+ PidName p = new PidName(pid);
+ pidNames.add(p);
+ }
+ networkmapFilterBuilder.setPid(pidNames);
+
+ if (addressTypes != null) {
+ List<Class<? extends AddressTypeBase>> addressTypeList = new LinkedList<>();
+ for(String addressType : addressTypes){
+ Class<? extends AddressTypeBase> type = getAddressTypeByName(addressType, path, rtx);
+ addressTypeList.add(type);
+ }
+ networkmapFilterBuilder.setAddressType(addressTypeList);
+ }
+
+ networkmapRequestBuilder.setNetworkmapFilter(networkmapFilterBuilder.build());
+
+ queryInputBuilder.setType(ResourceTypeNetworkmap.class);
+ queryInputBuilder.setRequest(networkmapRequestBuilder.build());
+ queryInputBuilder.setServiceReference(ctagIID);
+ return queryInputBuilder.build();
+ }
+
+ public InstanceIdentifier<ContextTag> getResourceByPath(String path, ReadTransaction transaction){
+ //get iid from (list Records)
+ InstanceIdentifier<Record> recordIID = InstanceIdentifier.builder(Records.class).child(Record.class, new RecordKey(new Uri(path))).build();
+ Future<Optional<Record>> recordFuture = transaction.read(LogicalDatastoreType.CONFIGURATION, recordIID);
+ Optional<Record> optional = null;
+ try{
+ optional = recordFuture.get();
+ }catch(Exception e){
+ LOG.error("Reading Record failed", e);
+ return null;
+ }
+ //grt resourceIID from nbr-networkmap.yang
+ InstanceIdentifier<?> record2resourceIID = null;
+ if(optional.isPresent()) {
+ record2resourceIID = optional.get().getResourceIid();
+ }
+ InstanceIdentifier<Resource> resourceIID = (InstanceIdentifier<Resource>)record2resourceIID;
+ Future<Optional<Resource>> resourceFuture = transaction.read(LogicalDatastoreType.OPERATIONAL, resourceIID);
+ Optional<Resource> optional1 = null;
+ try{
+ optional1 = resourceFuture.get();
+ }
+ catch(Exception e){
+ LOG.error("Read resource failed:", e);
+ return null;
+ }
+ Resource resource = null;
+ if(optional1.isPresent())
+ resource = optional1.get();
+ InstanceIdentifier<ContextTag> finalresourceIID = resourceIID.child(ContextTag.class, new ContextTagKey(resource.getDefaultTag()));
+ return finalresourceIID;
+
+ }
+
+ public Class<? extends AddressTypeBase> getAddressTypeByName(String addressType,String path, ReadTransaction rtx){
+
+ InstanceIdentifier<Record> resourceIID = InstanceIdentifier.builder(Records.class).child(Record.class , new RecordKey(new Uri(path))).build();
+ InstanceIdentifier<AddressTypeMapping> atmIID = resourceIID.child(AddressTypeMapping.class, new AddressTypeMappingKey(addressType));
+ Future<Optional<AddressTypeMapping>> future = rtx.read(LogicalDatastoreType.CONFIGURATION, atmIID);
+ Optional<AddressTypeMapping> optional = null;
+ try{
+ optional = future.get();
+ }catch (Exception e) {
+ LOG.error("Reading AddressTypeMapping failed:",e);
+ return null;
+ }
+
+ Class<? extends AddressTypeBase> addressClass = optional.get().getAddressType();
+ return addressClass;
+
+ }
+
+ protected RFC7285NetworkMap.Meta buildMeta(InstanceIdentifier<?> iid) {
+ RFC7285NetworkMap.Meta meta = new RFC7285NetworkMap.Meta();
+ meta.vtag.rid = iid.firstKeyOf(Resource.class).getResourceId().getValue();
+ meta.vtag.tag = iid.firstKeyOf(ContextTag.class).getTag().getValue();
+ return meta;
+ }
+
+ protected Response buildOutput(QueryInput input, QueryOutput output) throws JsonProcessingException{
+ //TODO
+ NetworkmapResponse nmResponse = (NetworkmapResponse) output.getResponse();
+ NetworkMap networkMap = nmResponse.getNetworkMap();
+
+ RFC7285NetworkMap rfcnetworkmap = new RFC7285NetworkMap();
+ List<Partition> partition = networkMap.getPartition();
+
+ Map<String, AddressGroup> rfcNetowrkMap = new HashMap<String, AddressGroup>();
+ for(int i = 0 ;i < partition.size(); i++){
+
+ AddressGroup addressGroup = new AddressGroup();
+ String pidName = partition.get(i).getPid().getValue();
+
+ Ipv6PrefixList ipv6List = partition.get(i).getAugmentation(Ipv6PrefixList.class);
+ List<String> ipv6ListString = new ArrayList<String>();
+
+ Ipv4PrefixList ipv4List = partition.get(i).getAugmentation(Ipv4PrefixList.class);
+ List<String> ipv4ListString = new ArrayList<String>();
+
+ if(ipv6List != null) {
+ for (Ipv6Prefix ipv6 : ipv6List.getIpv6()) {
+ ipv6ListString.add(ipv6.getValue());
+ }
+ }
+ addressGroup.ipv6 = ipv6ListString;
+
+ if(ipv4List != null){
+ for (Ipv4Prefix ipv4 :ipv4List.getIpv4()){
+ ipv4ListString.add(ipv4.getValue());
+ }
+ }
+ addressGroup.ipv4 = ipv4ListString;
+
+ rfcNetowrkMap.put(pidName, addressGroup);
+ }
+
+ rfcnetworkmap.map = rfcNetowrkMap;
+
+ rfcnetworkmap.meta = buildMeta(input.getServiceReference());
+
+ String responseString = mapper.writeValueAsString(rfcnetworkmap);
+
+ return Response.ok(responseString, ALTO_NETWORKMAP).build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Yale University and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.alto.core.northbound.route.networkmap.impl;
+
+import javax.ws.rs.core.Response;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class NetworkmapRouteChecker {
+
+ public static Response checkMissing(JsonNode target, String field, String origin) {
+ if (target == null) {
+ // TODO :: report missing field, something like
+ // return new AltoMissingFieldError(field, origin);
+ return null;
+ }
+ return null;
+ }
+
+ public static Response checkList(JsonNode list, String field, String origin) {
+ if (!list.isArray()) {
+ // TODO :: report invalid field type, something like
+ // return new AltoInvalidFieldType(field, "array", origin);
+ return null;
+ }
+ return null;
+ }
+
+}
--- /dev/null
+package org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.impl.rev151021;
+
+import org.opendaylight.alto.core.northbound.route.networkmap.impl.AltoNorthboundRouteNetworkmap;
+
+public class AltoNorthboundRouteNetworkmapModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.impl.rev151021.AbstractAltoNorthboundRouteNetworkmapModule {
+ public AltoNorthboundRouteNetworkmapModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public AltoNorthboundRouteNetworkmapModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.impl.rev151021.AltoNorthboundRouteNetworkmapModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void customValidation() {
+ // add custom validation form module attributes here.
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ AltoNorthboundRouteNetworkmap networkmap = new AltoNorthboundRouteNetworkmap();
+ getBrokerDependency().registerProvider(networkmap);
+ networkmap.register(getAltoNorthboundRouterDependency());
+
+ return networkmap;
+ }
+
+}
--- /dev/null
+/*
+* Generated file
+*
+* Generated from: yang module name: alto-northbound-route-networkmap-impl yang module local name: alto-northbound-route-networkmap-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Thu Nov 05 12:06:09 CST 2015
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.impl.rev151021;
+public class AltoNorthboundRouteNetworkmapModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.impl.rev151021.AbstractAltoNorthboundRouteNetworkmapModuleFactory {
+
+}
--- /dev/null
+module alto-northbound-route-networkmap-impl {
+ yang-version 1;
+ namespace "urn:opendaylight:alto:core:northbound:route:networkmap:impl";
+ prefix "alto-northbound-router-networkmap-impl";
+
+ import alto-northbound { prefix alto-northbound; revision-date 2015-10-21; }
+ import config { prefix config; revision-date 2013-04-05; }
+ import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
+
+ description
+ "Service definition for northbound project";
+
+ revision "2015-10-21" {
+ description
+ "Initial revision";
+ }
+
+ identity alto-northbound-route-networkmap-impl {
+ base config:module-type;
+ config:java-name-prefix AltoNorthboundRouteNetworkmap;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case alto-northbound-route-networkmap {
+ when "/config:modules/config:module/config:type = 'alto-northbound-route-networkmap-impl'";
+ container broker {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity md-sal-binding:binding-broker-osgi-registry;
+ }
+ }
+ }
+
+ container alto-northbound-router {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity alto-northbound:alto-northbound-router;
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2015 Yale University and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.impl.rev151021;
+
+import org.junit.Test;
+
+public class AltoNorthboundRouteNetworkmapModuleFactoryTest {
+ @Test
+ public void testFactoryConstructor() {
+ // ensure no exceptions on construction
+ new AltoNorthboundRouteNetworkmapModuleFactory();
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2015 Yale University and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yang.gen.v1.urn.opendaylight.alto.core.northbound.route.networkmap.impl.rev151021;
+
+import org.junit.Test;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.JmxAttribute;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.alto.core.northbound.api.AltoNorthboundRouter;
+
+import javax.management.ObjectName;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class AltoNorthboundRouteNetworkmapModuleTest {
+ @Test
+ public void testCustomValidation() {
+ AltoNorthboundRouteNetworkmapModule module = new AltoNorthboundRouteNetworkmapModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
+
+ // ensure no exceptions on validation
+ // currently this method is empty
+ module.customValidation();
+ }
+
+ @Test
+ public void testCreateInstance() throws Exception {
+ // configure mocks
+ DependencyResolver dependencyResolver = mock(DependencyResolver.class);
+ BindingAwareBroker broker = mock(BindingAwareBroker.class);
+ AltoNorthboundRouter router = mock(AltoNorthboundRouter.class);
+ when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
+ when(dependencyResolver.resolveInstance(eq(AltoNorthboundRouter.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(router);
+
+ // create instance of module with injected mocks
+ AltoNorthboundRouteNetworkmapModule module = new AltoNorthboundRouteNetworkmapModule(mock(ModuleIdentifier.class), dependencyResolver);
+
+ // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
+ AutoCloseable closeable = module.getInstance();
+
+ // ensure no exceptions on close
+ closeable.close();
+
+ // verify that the route is released after closed
+ verify(router).removeRoute("networkmap");
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright © 2015 Copyright (c) Yale University and others. All rights reserved.
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>odlparent</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.opendaylight.alto.core</groupId>
+ <artifactId>routes-networkmap-aggregator</artifactId>
+ <version>0.2.0-SNAPSHOT</version>
+ <name>alto-northbound-route-networkmap-aggregator</name>
+ <packaging>pom</packaging>
+ <modelVersion>4.0.0</modelVersion>
+ <prerequisites>
+ <maven>3.1.1</maven>
+ </prerequisites>
+
+ <profiles>
+ <profile>
+ <id>minimal</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>api</module>
+ <module>impl</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <id>alto-test</id>
+ <modules>
+ <module>api</module>
+ <module>impl</module>
+ </modules>
+ </profile>
+ </profiles>
+ <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
- <!--
<modules>
<module>networkmap</module>
</modules>
- -->
</profile>
<profile>
<id>alto-dev</id>
<modules>
<module>example</module>
+ <module>networkmap</module>
</modules>
</profile>
<classifier>config</classifier>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.alto.core</groupId>
+ <artifactId>alto-northbound-route-networkmap-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.alto.core</groupId>
+ <artifactId>alto-northbound-route-networkmap-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.alto.core</groupId>
+ <artifactId>alto-northbound-route-networkmap-impl</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>config</classifier>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.alto.core</groupId>
<artifactId>alto-service-model-ird-api</artifactId>
<feature name='odl-alto-standard-northbound-route' version='${project.version}'
description='OpenDaylight :: alto :: standard-northbound-route'>
<!-- TODO standard routes for network map/cost map/endpoint cost/endpoint property -->
+ <feature version='${project.version}'>odl-alto-standard-service-models</feature>
+ <feature version='${project.version}'>odl-alto-northbound</feature>
+
+ <bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-api/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-impl/${project.version}</bundle>
+ <configfile finalname="${configfile.directory}/alto-northbound-route-networkmap.xml">
+ mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-impl/${project.version}/xml/config
+ </configfile>
</feature>
<feature name='odl-alto-standard-resource-translator' version='${project.version}'
--- /dev/null
+#!/bin/bash
+
+NETWORKMAP_PATH=$1
+RESOURCE_ID=$2
+if [ $3 ]; then
+ CONTEXT_ID=$3
+else
+ CONTEXT_ID="00000000-0000-0000-0000-000000000000"
+fi
+
+DATA=$(cat ./northbound/template/nbr-record-networkmap \
+ | sed 's/\$1/'$NETWORKMAP_PATH'/g' \
+ | sed 's/\$2/'$CONTEXT_ID'/g' \
+ | sed 's/\$3/'$RESOURCE_ID'/g')
+
+# echo $DATA | python -m json.tool
+
+curl -X PUT -u admin:admin -H "Content-Type: application/json" \
+ -d "$DATA" \
+ http://localhost:8181/restconf/config/alto-nbr-networkmap:records/record/$NETWORKMAP_PATH
--- /dev/null
+#!/bin/bash
+
+NETWORKMAP_PATH=$1
+
+DATA=$(cat ./northbound/template/networkmap-filter)
+
+# echo $DATA | python -m json.tool
+
+curl -X POST -u admin:admin -H "Content-Type: application/alto-networkmapfilter+json" \
+ -d "$DATA" \
+ http://localhost:8080/alto/networkmap/$NETWORKMAP_PATH
--- /dev/null
+{
+ "record": {
+ "path": "$1",
+ "resource-iid": "/alto-resourcepool:context[alto-resourcepool:context-id='$2']/alto-resourcepool:resource[alto-resourcepool:resource-id='$3']",
+ "address-type-mapping": [
+ {
+ "address-type-string": "ipv4",
+ "address-type": "alto-model-networkmap:address-type-ipv4"
+ },
+ {
+ "address-type-string": "ipv6",
+ "address-type": "alto-model-networkmap:address-type-ipv6"
+ }
+ ]
+ }
+}
--- /dev/null
+{
+ "pids": ["PID1", "PID2"],
+ "address-types": ["ipv4", "ipv6"]
+}