import org.opendaylight.alto.commons.types.model150404.ModelCostMapData;
import org.opendaylight.alto.commons.types.rfc7285.RFC7285CostMap;
-public class RFC2ModelCostMapConverter
+public class RFC2ModelCostMapConverter
extends Converter<RFC7285CostMap, ModelCostMap>{
protected RFC2ModelCostMapMetaConverter metaConv = new RFC2ModelCostMapMetaConverter();
protected RFC2ModelCostMapDataConverter dataConv = new RFC2ModelCostMapDataConverter();
-
+
public RFC2ModelCostMapConverter() {
}
public RFC2ModelCostMapConverter(RFC7285CostMap _in) {
super(_in);
}
-
+
@Override
protected Object _convert() {
ModelCostMap out = new ModelCostMap();
out.rid = getCostMapResourceId(in());
//TODO: replace the dummy one in the future
out.tag = "da65eca2eb7a10ce8b059740b0b2e3f8eb1d4786";
-
+
out.meta = metaConv.convert(in().meta);
out.map = new LinkedList<ModelCostMapData>();
for (String src : in().map.keySet()) {
}
return out;
}
-
+
private String getCostMapResourceId(RFC7285CostMap costMap) {
String networkMapRID = costMap.meta.netmap_tags.get(0).rid;
String costMetric = costMap.meta.costType.metric;
--- /dev/null
+package org.opendaylight.alto.commons.types.converter;
+
+import org.opendaylight.alto.commons.helper.Converter;
+
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285VersionTag;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285Endpoint;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class YANGJSON2RFCAddressGroupConverter extends Converter<JsonNode, RFC7285Endpoint.AddressGroup> {
+ public YANGJSON2RFCAddressGroupConverter() {
+ }
+
+ public YANGJSON2RFCAddressGroupConverter(JsonNode _in) {
+ super(_in);
+ }
+
+ @Override
+ protected Object _convert() {
+ JsonNode node = this.in();
+ RFC7285Endpoint.AddressGroup ag = new RFC7285Endpoint.AddressGroup();
+
+ for (JsonNode address: node) {
+ JsonNode prefixes = address.get("endpointPrefix");
+ assert !prefixes.isArray();
+ for (JsonNode prefix: prefixes) {
+ JsonNode ipv4 = prefix.get("ipv4Prefix");
+ JsonNode ipv6 = prefix.get("ipv6Prefix");
+ if ((ipv4 != null) && (!ipv4.isNull())) {
+ ag.ipv4.add(ipv4.get("value").asText());
+ }
+ if ((ipv6 != null) && (!ipv6.isNull())) {
+ ag.ipv6.add(ipv6.get("value").asText());
+ }
+ }
+ }
+ return ag;
+ }
+
+}
--- /dev/null
+package org.opendaylight.alto.commons.types.converter;
+
+import org.opendaylight.alto.commons.helper.Converter;
+
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285NetworkMap;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285VersionTag;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285Endpoint;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class YANGJSON2RFCNetworkMapConverter extends Converter<JsonNode, RFC7285NetworkMap> {
+ public YANGJSON2RFCNetworkMapConverter() {
+ }
+
+ public YANGJSON2RFCNetworkMapConverter(JsonNode _in) {
+ super(_in);
+ }
+
+ protected YANGJSON2RFCAddressGroupConverter group_converter
+ = new YANGJSON2RFCAddressGroupConverter();
+
+ @Override
+ protected Object _convert() {
+ JsonNode node = this.in();
+ RFC7285NetworkMap nm = new RFC7285NetworkMap();
+
+ String resource_id = node.get("resourceId").get("value").asText();
+ String tag = node.get("tag").get("value").asText();
+
+ nm.meta.vtag = new RFC7285VersionTag(resource_id, tag);
+
+ JsonNode map = node.get("map");
+ assert !map.isArray();
+ for (JsonNode egroup: map) {
+ String pid = extract_pid(egroup);
+ JsonNode addr_group = egroup.get("endpointAddressGroup");
+ assert addr_group.isNull();
+ RFC7285Endpoint.AddressGroup ag = group_converter.convert(addr_group);
+
+ nm.map.put(pid, ag);
+ }
+ return nm;
+ }
+
+ protected String extract_pid(JsonNode node) {
+ return node.get("pid").get("value").asText();
+ }
+}
.setSerializationInclusion(Include.NON_DEFAULT)
.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
+
public ModelNetworkMap asNetworkMap(String json) throws Exception {
return mapper.readValue(json, ModelNetworkMap.class);
}
-
+
public List<ModelNetworkMap> asNetworkMapList(String json) throws Exception {
return Arrays.asList(mapper.readValue(json, ModelNetworkMap[].class));
}
-
+
public ModelCostMap asCostMap(String json) throws Exception {
return mapper.readValue(json, ModelCostMap.class);
}
-
+
public List<ModelCostMap> asCostMapList(String json) throws Exception {
return Arrays.asList(mapper.readValue(json, ModelCostMap[].class));
}
-
+
public ModelEndpointPropertyMap asEndpointPropMap(String json) throws Exception {
return mapper.readValue(json, ModelEndpointPropertyMap.class);
}
= Pattern.compile("^["+VALID_CHARSET_WITH_DOT+"]{1,64}$");
private static final String VALID_TAG_CHARSET = "!-~";
private static final Pattern VALID_TAG_PATTERN
- = Pattern.compile("^["+VALID_TAG_CHARSET+"]{1,64}$}");
+ = Pattern.compile("^["+VALID_TAG_CHARSET+"]{1,64}$");
public static boolean validId(String id) {
return VALID_ID_PATTERN.matcher(id).matches();
public RFC7285CostMap asCostMap(String json) throws Exception {
return mapper.readValue(json, RFC7285CostMap.class);
}
-
+
public List<RFC7285CostMap> asCostMapList(String json) throws Exception {
return Arrays.asList(mapper.readValue(json, RFC7285CostMap[].class));
}
public RFC7285NetworkMap asNetworkMap(String json) throws Exception {
return mapper.readValue(json, RFC7285NetworkMap.class);
}
-
+
public List<RFC7285NetworkMap> asNetworkMapList(String json) throws Exception {
return Arrays.asList(mapper.readValue(json, RFC7285NetworkMap[].class));
}
public RFC7285VersionTag asVersionTag(String json) throws Exception {
return mapper.readValue(json, RFC7285VersionTag.class);
}
-
+
public RFC7285EndpointPropertyMap asEndpointPropMap(String json) throws Exception {
return mapper.readValue(json, RFC7285EndpointPropertyMap.class);
}
<extensions>true</extensions>
<configuration>
<instructions>
- <Import-Package>
- org.opendaylight.alto.services.api.rfc7285,
- org.opendaylight.alto.commons.types.rfc7285,
- org.slf4j,
- </Import-Package>
+ <Import-Package>*</Import-Package>
<Export-Package>
org.opendaylight.alto.ext.fake;
</Export-Package>
<instructions>
<Import-Package>
org.opendaylight.yang.gen.v1.urn.opendaylight.alto.*,
- org.opendaylight.alto.ext.fake,
org.opendaylight.alto.services.api.rfc7285,
org.opendaylight.alto.commons.*,
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924,
org.apache.commons.logging,
com.sun.jersey.spi.container.servlet,
- org.opendaylight.controller.northbound.commons,
- org.opendaylight.controller.northbound.commons.exception,
- org.opendaylight.controller.northbound.commons.utils,
org.opendaylight.controller.sal.utils,
org.opendaylight.controller.sal.authorization,
org.opendaylight.controller.sal.packet.address,
<version>${controller.commons.northbound.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-common-util</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
<artifactId>service-api-rfc7285</artifactId>
<version>${project.version}</version>
</dependency>
-
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>alto-fake-extension</artifactId>
- <version>${project.version}</version>
- </dependency>
</dependencies>
</project>
import org.opendaylight.alto.commons.types.rfc7285.RFC7285Endpoint;
import org.opendaylight.alto.services.api.rfc7285.AltoService;
+import org.opendaylight.alto.services.api.rfc7285.IRDService;
+import org.opendaylight.alto.services.api.rfc7285.NetworkMapService;
+import org.opendaylight.alto.services.api.rfc7285.CostMapService;
+import org.opendaylight.alto.services.api.rfc7285.EndpointCostService;
+import org.opendaylight.alto.services.api.rfc7285.EndpointPropertyService;
-import org.opendaylight.alto.ext.fake.FakeAltoService;
import org.opendaylight.alto.northbound.exception.AltoBasicException;
import org.opendaylight.alto.northbound.exception.AltoBadFormatException;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(AltoNorthbound.class);
- private AltoService altoService = new FakeAltoService();
private RFC7285JSONMapper mapper = new RFC7285JSONMapper();
- private void checkAltoService() throws Exception {
- if (altoService == null)
+ private <E> E getService(Class<E> clazz) {
+ E service = (E)ServiceHelper.getGlobalInstance(clazz, this);
+ if (service == null) {
+ service = (E)ServiceHelper.getGlobalInstance(AltoService.class, this);
+ }
+ return service;
+ }
+
+ private void checkService(Object service) throws Exception {
+ if (service == null)
throw new AltoBasicException(Status.SERVICE_UNAVAILABLE, null);
}
@GET
@Produces({ MediaType.ALTO_DIRECTORY, MediaType.ALTO_ERROR })
public Response retrieveIRD() throws Exception {
- checkAltoService();
+ IRDService service = getService(IRDService.class);
+ checkService(service);
- RFC7285IRD ird = altoService.getDefaultIRD();
+ RFC7285IRD ird = service.getDefaultIRD();
if (ird == null)
return fail(Status.NOT_FOUND, null);
return success(ird, MediaType.ALTO_DIRECTORY);
@Produces({ MediaType.ALTO_DIRECTORY, MediaType.ALTO_ERROR })
public Response retrieveIRD(
@PathParam("id") String id) throws Exception {
- checkAltoService();
+ IRDService service = getService(IRDService.class);
+ checkService(service);
checkResourceId(id);
- RFC7285IRD ird = altoService.getIRD(id);
+ RFC7285IRD ird = service.getIRD(id);
if (ird == null)
return fail(Status.NOT_FOUND, id);
return success(ird, MediaType.ALTO_DIRECTORY);
@GET
@Produces({ MediaType.ALTO_NETWORKMAP, MediaType.ALTO_ERROR })
public Response retrieveDefaultNetworkMap() throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
- RFC7285NetworkMap map = altoService.getDefaultNetworkMap();
+ RFC7285NetworkMap map = service.getDefaultNetworkMap();
if (map == null)
return fail(Status.NOT_FOUND, null);
return success(map, MediaType.ALTO_NETWORKMAP);
@Produces({ MediaType.ALTO_NETWORKMAP, MediaType.ALTO_ERROR })
public Response retrieveNetworkMap(
@PathParam("id") String id) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
- RFC7285NetworkMap map = altoService.getNetworkMap(id);
+ RFC7285NetworkMap map = service.getNetworkMap(id);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_NETWORKMAP);
public Response retrieveNetworkMap(
@PathParam("id") String id,
@PathParam("tag") String tag) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
- RFC7285NetworkMap map = altoService.getNetworkMap(vtag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285NetworkMap map = service.getNetworkMap(vtag);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_NETWORKMAP);
@GET
@Produces({ MediaType.ALTO_COSTMAP, MediaType.ALTO_ERROR})
public Response retrieveCostMap(@PathParam("id") String id) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
- RFC7285CostMap map = altoService.getCostMap(id);
+ RFC7285CostMap map = service.getCostMap(id);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_COSTMAP);
public Response retrieveCostMap(
@PathParam("id") String id,
@PathParam("tag") String tag) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
- RFC7285CostMap map = altoService.getCostMap(vtag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285CostMap map = service.getCostMap(vtag);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_COSTMAP);
@PathParam("id") String id,
@PathParam("mode") String mode,
@PathParam("metric") String metric) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
RFC7285CostType costType = new RFC7285CostType(mode, metric);
- if (!altoService.supportCostType(id, costType))
+ if (!service.supportCostType(id, costType))
return fail(Status.NOT_FOUND, costType);
- RFC7285CostMap map = altoService.getCostMap(id, costType);
+ RFC7285CostMap map = service.getCostMap(id, costType);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_COSTMAP);
@PathParam("tag") String tag,
@PathParam("mode") String mode,
@PathParam("metric") String metric) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285CostType costType = new RFC7285CostType(mode, metric);
- if (!altoService.supportCostType(vtag, costType))
+ if (!service.supportCostType(vtag, costType))
return fail(Status.NOT_FOUND, costType);
- RFC7285CostMap map = altoService.getCostMap(vtag, costType);
+ RFC7285CostMap map = service.getCostMap(vtag, costType);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_COSTMAP);
@Produces({ MediaType.ALTO_NETWORKMAP, MediaType.ALTO_ERROR})
public Response retrieveFilteredNetworkMap(
@PathParam("id") String id, String filterJSON) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
RFC7285NetworkMap.Filter filter = mapper.asNetworkMapFilter(filterJSON);
- if (!altoService.validateNetworkMapFilter(id, filter))
+ if (!service.validateNetworkMapFilter(id, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285NetworkMap map = altoService.getNetworkMap(id, filter);
+ RFC7285NetworkMap map = service.getNetworkMap(id, filter);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_NETWORKMAP);
@PathParam("id") String id,
@PathParam("tag") String tag,
String filterJSON) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285NetworkMap.Filter filter = mapper.asNetworkMapFilter(filterJSON);
- if (!altoService.validateNetworkMapFilter(vtag, filter))
+ if (!service.validateNetworkMapFilter(vtag, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285NetworkMap map = altoService.getNetworkMap(vtag, filter);
+ RFC7285NetworkMap map = service.getNetworkMap(vtag, filter);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_NETWORKMAP);
@Produces({ MediaType.ALTO_COSTMAP, MediaType.ALTO_ERROR})
public Response retrieveFilteredCostMap(
@PathParam("id") String id, String filterJSON) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
RFC7285CostMap.Filter filter = mapper.asCostMapFilter(filterJSON);
- if (!altoService.validateCostMapFilter(id, filter))
+ if (!service.validateCostMapFilter(id, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285CostMap map = altoService.getCostMap(id, filter);
+ RFC7285CostMap map = service.getCostMap(id, filter);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_COSTMAP);
public Response retrieveFilteredCostMap(
@PathParam("id") String id,
@PathParam("tag") String tag, String filterJSON) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285CostMap.Filter filter = mapper.asCostMapFilter(filterJSON);
- if (!altoService.validateCostMapFilter(vtag, filter))
+ if (!service.validateCostMapFilter(vtag, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285CostMap map = altoService.getCostMap(vtag, filter);
+ RFC7285CostMap map = service.getCostMap(vtag, filter);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_COSTMAP);
public Response retrieveEndpointPropMap(
@PathParam("id") String id,
String params) throws Exception {
- checkAltoService();
+ EndpointPropertyService service = getService(EndpointPropertyService.class);
+ checkService(service);
checkResourceId(id);
RFC7285Endpoint.PropertyRequest request = mapper.asPropertyRequest(params);
- RFC7285Endpoint.PropertyResponse response = altoService.getEndpointProperty(id, request);
+ RFC7285Endpoint.PropertyResponse response = service.getEndpointProperty(id, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_PROP);
@PathParam("id") String id,
@PathParam("tag") String tag,
String params) throws Exception {
- checkAltoService();
+ EndpointPropertyService service = getService(EndpointPropertyService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285Endpoint.PropertyRequest request = mapper.asPropertyRequest(params);
- RFC7285Endpoint.PropertyResponse response = altoService.getEndpointProperty(vtag, request);
+ RFC7285Endpoint.PropertyResponse response = service.getEndpointProperty(vtag, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_PROP);
public Response retrieveEndpointCostMap(
@PathParam("id") String id,
String params) throws Exception {
- checkAltoService();
+ EndpointCostService service = getService(EndpointCostService.class);
+ checkService(service);
checkResourceId(id);
RFC7285Endpoint.CostRequest request = mapper.asCostRequest(params);
- RFC7285Endpoint.CostResponse response = altoService.getEndpointCost(id, request);
+ RFC7285Endpoint.CostResponse response = service.getEndpointCost(id, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_COST);
@PathParam("id") String id,
@PathParam("tag") String tag,
String params) throws Exception {
- checkAltoService();
+ EndpointCostService service = getService(EndpointCostService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285Endpoint.CostRequest request = mapper.asCostRequest(params);
- RFC7285Endpoint.CostResponse response = altoService.getEndpointCost(vtag, request);
+ RFC7285Endpoint.CostResponse response = service.getEndpointCost(vtag, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_COST);
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(AltoNorthbound.class);
- classes.add(Echo.class);
return classes;
}
}
<packaging>pom</packaging>
<modules>
+ <module>simple-alto</module>
</modules>
</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<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.3.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.alto</groupId>
+ <artifactId>simple-impl</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alto-commons</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>service-api-rfc7285</artifactId>
+ <version>${project.version}</version>
+ </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>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-config</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-inet-types</artifactId>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+<snapshot>
+ <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:alto-simple="urn:opendaylight:alto:simple-impl">
+ alto-simple:simple-alto-adsal-impl
+ </type>
+ <name>simple-alto-adsal-impl</name>
+
+ <data-broker>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">
+ binding:binding-async-data-broker
+ </type>
+ <name>binding-data-broker</name>
+ </data-broker>
+ </module>
+ </modules>
+ </data>
+ </configuration>
+
+ <required-capabilities>
+ <capability>urn:opendaylight:alto:simple-impl?module=simple-alto-adsal-impl&revision=2015-05-12</capability>
+ </required-capabilities>
+</snapshot>
--- /dev/null
+package org.opendaylight.alto.services.provider.simple;
+
+import org.opendaylight.alto.services.api.rfc7285.NetworkMapService;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285NetworkMap;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285Endpoint;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285VersionTag;
+import org.opendaylight.alto.commons.types.converter.YANGJSON2RFCNetworkMapConverter;
+
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.Resources;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.IRD;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.NetworkMaps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.network.maps.NetworkMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.network.maps.NetworkMapKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.ResourceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.ird.meta.DefaultAltoNetworkMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.ird.Meta;
+
+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.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.osgi.framework.ServiceRegistration;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.AsyncFunction;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
+import java.util.LinkedHashMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class SimpleAltoService implements NetworkMapService, AutoCloseable {
+
+ private final Logger m_logger = LoggerFactory.getLogger(SimpleAltoService.class);
+ private DataBroker m_db = null;
+ private ObjectMapper m_mapper = new ObjectMapper();
+ private ServiceRegistration m_reg = null;
+ private YANGJSON2RFCNetworkMapConverter m_converter = null;
+
+ public SimpleAltoService(DataBroker db) {
+ this.m_db = db;
+ this.m_reg = ServiceHelper.registerGlobalServiceWReg(NetworkMapService.class, this, null);
+ this.m_converter = new YANGJSON2RFCNetworkMapConverter();
+ assert ServiceHelper.getGlobalInstance(NetworkMapService.class, this) != this;
+ }
+
+ @Override
+ public void close() {
+ this.m_reg.unregister();
+ }
+
+ @Override
+ public RFC7285NetworkMap getDefaultNetworkMap() {
+ //TODO
+ return null;
+ }
+
+ @Override
+ public RFC7285NetworkMap getNetworkMap(String id) {
+ m_logger.info("Handling resource-id: {}", id);
+ InstanceIdentifier<NetworkMap> niid = getNetworkMapIID(id);
+ m_logger.info("IID: {}", niid);
+
+ try {
+ ReadOnlyTransaction tx = m_db.newReadOnlyTransaction();
+ ListenableFuture<Optional<NetworkMap>> result
+ = tx.read(LogicalDatastoreType.CONFIGURATION, niid);
+ if (result.get().isPresent()) {
+ NetworkMap nm = result.get().get();
+ ObjectNode node = m_mapper.valueToTree(nm);
+ m_logger.info(m_mapper.writeValueAsString(nm));
+
+ RFC7285NetworkMap ret = m_converter.convert(node);
+ return ret;
+ } else {
+ m_logger.info("Failed to read with niid: {}", niid);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public RFC7285NetworkMap getNetworkMap(RFC7285VersionTag vtag) {
+ RFC7285NetworkMap nm = getNetworkMap(vtag.rid);
+
+ if ((nm != null) && (vtag.equals(nm.meta.vtag))) {
+ return nm;
+ }
+ return null;
+ }
+
+ @Override
+ public RFC7285NetworkMap getNetworkMap(String id, RFC7285NetworkMap.Filter filter) {
+ RFC7285NetworkMap nm = getNetworkMap(id);
+
+ if (nm == null)
+ return null;
+
+ LinkedHashMap<String, RFC7285Endpoint.AddressGroup> map
+ = new LinkedHashMap<String, RFC7285Endpoint.AddressGroup>();
+ for (String pid: filter.pids) {
+ if (nm.map.containsKey(pid))
+ map.put(pid, nm.map.get(pid));
+ }
+ nm.map = map;
+ return nm;
+ }
+
+ @Override
+ public RFC7285NetworkMap getNetworkMap(RFC7285VersionTag vtag, RFC7285NetworkMap.Filter filter) {
+ RFC7285NetworkMap nm = getNetworkMap(vtag.rid, filter);
+ if ((nm != null) && (vtag.equals(nm.meta.vtag))) {
+ return nm;
+ }
+ return null;
+ }
+
+ @Override
+ public Boolean validateNetworkMapFilter(String id, RFC7285NetworkMap.Filter filter) {
+ if ((filter != null) && (filter.pids != null))
+ return true;
+ return false;
+ }
+
+ @Override
+ public Boolean validateNetworkMapFilter(RFC7285VersionTag vtag, RFC7285NetworkMap.Filter filter) {
+ return validateNetworkMapFilter(vtag.rid, filter);
+ }
+
+ protected InstanceIdentifier<DefaultAltoNetworkMap> getDefaultNetworkMapIID() {
+ InstanceIdentifier<DefaultAltoNetworkMap> iid = InstanceIdentifier.builder(Resources.class)
+ .child(IRD.class)
+ .child(Meta.class)
+ .child(DefaultAltoNetworkMap.class).build();
+ return iid;
+ }
+
+ protected InstanceIdentifier<NetworkMap> getNetworkMapIID(String resource_id) {
+ NetworkMapKey key = new NetworkMapKey(ResourceId.getDefaultInstance(resource_id));
+ InstanceIdentifier<NetworkMap> iid = InstanceIdentifier.builder(Resources.class)
+ .child(NetworkMaps.class)
+ .child(NetworkMap.class, key)
+ .build();
+ return iid;
+ }
+}
--- /dev/null
+package org.opendaylight.yang.gen.v1.urn.opendaylight.alto.simple.impl.rev150512;
+
+import org.opendaylight.alto.services.provider.simple.SimpleAltoService;
+
+public class SimpleAltoImplModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.alto.simple.impl.rev150512.AbstractSimpleAltoImplModule {
+ public SimpleAltoImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public SimpleAltoImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.alto.simple.impl.rev150512.SimpleAltoImplModule 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() {
+ SimpleAltoService service = new SimpleAltoService(this.getDataBrokerDependency());
+ return service;
+ }
+
+}
--- /dev/null
+/*
+* Generated file
+*
+* Generated from: yang module name: simple-alto-adsal-impl yang module local name: simple-alto-adsal-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Tue May 12 16:43:21 CST 2015
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.urn.opendaylight.alto.simple.impl.rev150512;
+public class SimpleAltoImplModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.alto.simple.impl.rev150512.AbstractSimpleAltoImplModuleFactory {
+
+}
--- /dev/null
+module simple-alto-adsal-impl {
+ yang-version 1;
+ namespace "urn:opendaylight:alto:simple-impl";
+
+ prefix alto-simple;
+
+ import config {
+ prefix config;
+ revision-date 2013-04-05;
+ }
+
+ import opendaylight-md-sal-binding {
+ prefix mdsal;
+ revision-date 2013-10-28;
+ }
+
+ description
+ "This module contains the base YANG definition for adsal-based northbound services";
+
+ revision "2015-05-12" {
+ description "Initial revision";
+ }
+
+ identity simple-alto-adsal-impl {
+ base config:module-type;
+
+ config:java-name-prefix SimpleAltoImpl;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case simple-alto-adsal-impl {
+ when "/config:modules/config:module/config:type = 'simple-alto-adsal-impl'";
+
+ container data-broker {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity mdsal:binding-async-data-broker;
+ }
+ }
+ }
+ }
+ }
+}
<properties>
<features.file>features.xml</features.file>
+ <configfile.directory>etc/opendaylight/karaf</configfile.directory>
</properties>
<dependencyManagement>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>features-adsal</artifactId>
+ <version>${sal.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>features-restconf</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>simple-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>simple-impl</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>config</classifier>
+ </dependency>
+
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>alto-northbound</artifactId>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
<repository>mvn:org.opendaylight.yangtools/features-yangtools/${yangtools.version}/xml/features</repository>
+ <repository>mvn:org.opendaylight.controller/features-adsal/${sal.version}/xml/features</repository>
<repository>mvn:org.opendaylight.controller/features-mdsal/${mdsal.version}/xml/features</repository>
<repository>mvn:org.opendaylight.controller/features-restconf/${mdsal.version}/xml/features</repository>
<repository>mvn:org.opendaylight.controller/features-base/${odl.version}/xml/features</repository>
<feature name='odl-alto-commons' version='${project.version}' description='OpenDaylight :: alto :: utils'>
<feature version='${project.version}'>odl-alto-model</feature>
<feature version='${jackson.version}'>odl-base-jackson</feature>
+ <feature version='7.0.53'>odl-base-tomcat</feature>
<bundle>mvn:org.opendaylight.alto/alto-commons/${project.version}</bundle>
</feature>
<feature version='${mdsal.version}'>odl-mdsal-broker</feature>
<feature version='${l2switch.version}'>odl-l2switch-hosttracker</feature>
<feature version='${l2switch.version}'>odl-l2switch-addresstracker</feature>
- <configfile finalname="etc/opendaylight/karaf/03-alto.xml">mvn:org.opendaylight.alto/alto-config/${project.version}/xml/config</configfile>
+ <configfile finalname="${configfile.directory}/03-alto.xml">mvn:org.opendaylight.alto/alto-config/${project.version}/xml/config</configfile>
<bundle>mvn:org.opendaylight.alto/alto-provider/${project.version}</bundle>
</feature>
<bundle>mvn:org.opendaylight.alto/alto-services/${project.version}</bundle>
</feature>
+ <feature name='odl-alto-simple' version='${project.version}' description='OpenDaylight :: alto :: Simple'>
+ <feature version='${project.version}'>odl-alto-commons</feature>
+ <feature version='${mdsal.version}'>odl-mdsal-common</feature>
+ <feature version='${mdsal.version}'>odl-mdsal-broker</feature>
+ <feature version='${sal.version}'>odl-adsal-core</feature>
+ <bundle>mvn:org.opendaylight.alto/simple-impl/${project.version}</bundle>
+ <configfile finalname='${configfile.directory}/alto-simple.xml'>mvn:org.opendaylight.alto/simple-impl/${project.version}/xml/config</configfile>
+ </feature>
+
<feature name='odl-alto-northbound' version='${project.version}' description='Opendaylight :: alto :: Northbound'>
<feature version='${jersey.version}'>odl-base-jersey</feature>
<feature>war</feature>
<feature version='${project.version}'>odl-alto-commons</feature>
+ <feature version='${project.version}'>odl-alto-simple</feature>
<bundle>mvn:org.opendaylight.alto/service-api-rfc7285/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.alto/services.ext.fake/${project.version}</bundle>
<bundle>mvn:org.opendaylight.alto/alto-northbound/${project.version}</bundle>
</feature>
<module>alto-commons</module>
<module>alto-manager</module>
<module>alto-services/api</module>
+ <module>alto-services/provider</module>
<module>alto-extensions</module>
<!-- <module>alto-karaf</module> -->
<module>alto-northbound</module>
TODO: need more investigation -->
<config.version>0.3.0-SNAPSHOT</config.version>
- <sal.version>0.7.1-SNAPSHOT</sal.version>
+ <sal.version>0.9.0-SNAPSHOT</sal.version>
<war.version>${karaf.version}</war.version>
<mdsal.version>1.2.0-SNAPSHOT</mdsal.version>
<jmxGeneratorPath>src/main/yang-gen-config</jmxGeneratorPath>
</controller.commons.northbound.version>
<l2switch.version>0.2.0-SNAPSHOT</l2switch.version>
<ietf.topology.version>2013.10.21.7-SNAPSHOT</ietf.topology.version>
+ <commons.catalina.version>7.0.53.v201406061610</commons.catalina.version>
</properties>
<dependencyManagement>