Fix cost field bug and several other bugs. 38/25338/1
authorjensenzhang <jingxuan.n.zhang@gmail.com>
Sun, 16 Aug 2015 21:01:39 +0000 (05:01 +0800)
committerjensenzhang <jingxuan.n.zhang@gmail.com>
Sun, 16 Aug 2015 21:01:39 +0000 (05:01 +0800)
Change-Id: I169fd0cdd5d1e2cb99f1bbde7319a961278d4d5a
Signed-off-by: jensenzhang <jingxuan.n.zhang@gmail.com>
27 files changed:
alto-commons/src/main/java/org/opendaylight/alto/commons/helper/NetworkMapIpPrefixHelper.java [new file with mode: 0644]
alto-commons/src/main/java/org/opendaylight/alto/commons/types/Subnet.java [new file with mode: 0644]
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelCostMapConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelCostMapDataConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelEndpointPropMapConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/YANGJSON2RFCCostMapConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelCostMapMeta.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelDstCosts.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelEndpointProperties.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/FormatValidator.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/RFC7285CostMap.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/RFC7285Endpoint.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/RFC7285IRD.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/RFC7285NetworkMap.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/RFC7285QueryPairs.java
alto-commons/src/test/java/org/opendaylight/alto/commons/types/rfc7285/TestRFC7285Types.java
alto-hosttracker/model/src/main/yang-gen-code/org/opendaylight/yang/gen/v1/urn/opendaylight/alto/hosttracker/rev150416/$YangModuleInfoImpl.java
alto-model/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/alto/service/types/rev150404/MediaTypeBuilder.java
alto-model/src/main/yang/alto-cost-default.yang
alto-model/src/main/yang/alto-service-types.yang
alto-northbound/pom.xml
alto-provider/pom.xml
alto-provider/src/main/java/org/opendaylight/alto/provider/AltoProvider.java
alto-provider/src/main/yang-gen-sal/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/alto/provider/impl/rev141119/$YangModuleInfoImpl.java
alto-provider/src/test/java/org/opendaylight/alto/provider/AltoProviderTest.java
alto-services/provider/simple-alto/src/main/yang/simple-alto.yang
pom.xml

diff --git a/alto-commons/src/main/java/org/opendaylight/alto/commons/helper/NetworkMapIpPrefixHelper.java b/alto-commons/src/main/java/org/opendaylight/alto/commons/helper/NetworkMapIpPrefixHelper.java
new file mode 100644 (file)
index 0000000..f546267
--- /dev/null
@@ -0,0 +1,77 @@
+package org.opendaylight.alto.commons.helper;
+
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.opendaylight.alto.commons.types.Subnet;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.network.maps.NetworkMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.PidName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.TypedEndpointAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.address.group.EndpointAddressGroup;
+
+public class NetworkMapIpPrefixHelper {
+    private Map<IpPrefix, PidName> prefixToPID = new HashMap<IpPrefix, PidName>();
+    private Map<IpPrefix, Subnet> prefixToSubnet = new HashMap<IpPrefix, Subnet>();
+    private boolean initiated = false;
+
+    public void update(NetworkMap networkMap) throws UnknownHostException {
+        clear();
+        if (networkMap == null) {
+            return;
+        }
+
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.network.map.Map map : networkMap
+                .getMap()) {
+            for (EndpointAddressGroup group : map.getEndpointAddressGroup()) {
+                for (IpPrefix prefix : group.getEndpointPrefix()) {
+                    this.prefixToPID.put(prefix, map.getPid());
+                    this.prefixToSubnet.put(prefix,
+                            new Subnet(group.getAddressType(), prefix));
+                }
+            }
+        }
+        initiated = true;
+    }
+
+    public void clear() {
+        this.initiated = false;
+        this.prefixToPID.clear();
+        this.prefixToSubnet.clear();
+    }
+
+    public boolean initiated() {
+        return this.initiated;
+    }
+
+    public Map<TypedEndpointAddress, PidName> getPIDsByEndpointAddresses(
+            List<TypedEndpointAddress> addresses) {
+        Map<TypedEndpointAddress, PidName> pids = new HashMap<TypedEndpointAddress, PidName>();
+        for (TypedEndpointAddress address : addresses) {
+            PidName pid = null;
+            try {
+                pid = getPIDByEndpointAddress(address);
+            } catch (UnknownHostException e) {
+                e.printStackTrace();
+            }
+            pids.put(address, pid);
+        }
+        return pids;
+    }
+
+    public PidName getPIDByEndpointAddress(TypedEndpointAddress address)
+            throws UnknownHostException {
+        int maxLen = -1;
+        PidName pid = null;
+        for (IpPrefix prefix : this.prefixToSubnet.keySet()) {
+            Subnet sn = this.prefixToSubnet.get(prefix);
+            if (sn.match(address) && sn.getSubnetLength() > maxLen) {
+                pid = this.prefixToPID.get(prefix);
+                maxLen = sn.getSubnetLength();
+            }
+        }
+        return pid;
+    }
+}
\ No newline at end of file
diff --git a/alto-commons/src/main/java/org/opendaylight/alto/commons/types/Subnet.java b/alto-commons/src/main/java/org/opendaylight/alto/commons/types/Subnet.java
new file mode 100644 (file)
index 0000000..70e8950
--- /dev/null
@@ -0,0 +1,133 @@
+package org.opendaylight.alto.commons.types;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.EndpointAddressType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.TypedEndpointAddress;
+
+public class Subnet {
+    private EndpointAddressType.Enumeration type;
+    private int bits;
+
+    private int ipv4Subnet;
+    private int ipv4Mask;
+
+    private int[] ipv6Subnet = new int[4];
+    private int[] ipv6Mask = new int[4];
+
+    private String prefix;
+
+    public Subnet(EndpointAddressType type, IpPrefix prefix)
+            throws UnknownHostException {
+        this.type = type.getEnumeration();
+
+        if (EndpointAddressType.Enumeration.Ipv4.equals(this.type)) {
+            subNet(prefix.getIpv4Prefix());
+            this.prefix = prefix.getIpv4Prefix().getValue();
+        } else if (EndpointAddressType.Enumeration.Ipv6.equals(this.type)) {
+            subNet(prefix.getIpv6Prefix());
+            this.prefix = prefix.getIpv6Prefix().getValue();
+        }
+    }
+
+    private void subNet(Ipv6Prefix ipv6Prefix) throws UnknownHostException {
+        String[] value = ipv6Prefix.getValue().split("[/]");
+        this.bits = Integer.parseInt(value[1]);
+        ipv6Mask();
+        this.ipv6Subnet = ipv6ToInt(value[0]);
+    }
+
+    private void ipv6Mask() {
+        if (this.bits <= 32) {
+            this.ipv6Mask[0] = -1 << (32 - this.bits);
+            this.ipv6Mask[1] = 0;
+            this.ipv6Mask[2] = 0;
+            this.ipv6Mask[3] = 0;
+        }
+
+        if (this.bits > 32 && this.bits <= 64) {
+            this.ipv6Mask[0] = -1;
+            this.ipv6Mask[1] = -1 << (64 - this.bits);
+            this.ipv6Mask[2] = 0;
+            this.ipv6Mask[3] = 0;
+        }
+
+        if (this.bits > 64 && this.bits <= 96) {
+            this.ipv6Mask[0] = -1;
+            this.ipv6Mask[1] = -1;
+            this.ipv6Mask[2] = -1 << (96 - this.bits);
+            this.ipv6Mask[3] = 0;
+        }
+
+        if (this.bits > 96 && this.bits <= 128) {
+            this.ipv6Mask[0] = -1;
+            this.ipv6Mask[1] = -1;
+            this.ipv6Mask[2] = -1;
+            this.ipv6Mask[3] = -1 << (128 - this.bits);
+        }
+    }
+
+    private void subNet(Ipv4Prefix ipv4Prefix) throws UnknownHostException {
+        String[] value = ipv4Prefix.getValue().split("/");
+        this.bits = Integer.parseInt(value[1]);
+        this.ipv4Mask = -1 << (32 - this.bits);
+        this.ipv4Subnet = ipv4ToInt(value[0]);
+    }
+
+    private int ipv4ToInt(String addr) throws UnknownHostException {
+        Inet4Address a = (Inet4Address) InetAddress.getByName(addr);
+        byte[] b = a.getAddress();
+        int addrInt = ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16)
+                | ((b[2] & 0xFF) << 8) | ((b[3] & 0xFF) << 0);
+        return addrInt;
+    }
+
+    private int[] ipv6ToInt(String address) throws UnknownHostException {
+        Inet6Address addr = (Inet6Address) InetAddress.getByName(address);
+        byte[] b = addr.getAddress();
+        int addr1 = ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16)
+                | ((b[2] & 0xFF) << 8) | ((b[3] & 0xFF) << 0);
+
+        int addr2 = ((b[4] & 0xFF) << 24) | ((b[5] & 0xFF) << 16)
+                | ((b[6] & 0xFF) << 8) | ((b[7] & 0xFF) << 0);
+
+        int addr3 = ((b[8] & 0xFF) << 24) | ((b[9] & 0xFF) << 16)
+                | ((b[10] & 0xFF) << 8) | ((b[11] & 0xFF) << 0);
+
+        int addr4 = ((b[12] & 0xFF) << 24) | ((b[13] & 0xFF) << 16)
+                | ((b[14] & 0xFF) << 8) | ((b[15] & 0xFF) << 0);
+        int[] addrs = { addr1, addr2, addr3, addr4 };
+        return addrs;
+    }
+
+    public boolean match(TypedEndpointAddress address)
+            throws UnknownHostException {
+        if (EndpointAddressType.Enumeration.Ipv4.equals(this.type) && address.getTypedIpv4Address() != null) {
+            int addr = ipv4ToInt(address.getTypedIpv4Address().getValue().replace("ipv4:", ""));
+            return ((ipv4Subnet & ipv4Mask) == (addr & ipv4Mask));
+        }
+
+        if (EndpointAddressType.Enumeration.Ipv6.equals(this.type) && address.getTypedIpv6Address() != null) {
+            int[] addr = ipv6ToInt(address.getTypedIpv6Address().getValue().replace("ipv6:", ""));
+            return ((ipv6Subnet[0] & ipv6Mask[0]) == (addr[0] & ipv6Mask[0]))
+                    && ((ipv6Subnet[1] & ipv6Mask[1]) == (addr[1] & ipv6Mask[1]))
+                    && ((ipv6Subnet[2] & ipv6Mask[2]) == (addr[2] & ipv6Mask[2]))
+                    && ((ipv6Subnet[3] & ipv6Mask[3]) == (addr[3] & ipv6Mask[3]));
+        }
+        return false;
+    }
+
+    public int getSubnetLength() {
+        return this.bits;
+    }
+
+    public String getIpPrefix() {
+        return this.prefix;
+    }
+}
index 1f9114655a0de41c46592927ee0e1e907aff42f9..c8408578b1480b7eb9862b7869ce9fba233d923f 100644 (file)
@@ -13,43 +13,40 @@ import java.util.LinkedList;
 import org.opendaylight.alto.commons.helper.Converter;
 import org.opendaylight.alto.commons.types.model150404.ModelCostMap;
 import org.opendaylight.alto.commons.types.model150404.ModelCostMapData;
+import org.opendaylight.alto.commons.types.model150404.ModelCostMapMeta;
 import org.opendaylight.alto.commons.types.rfc7285.RFC7285CostMap;
 
-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()) {
-      ModelCostMapData data = new ModelCostMapData();
-      data.src = src;
-      data.dstCosts = dataConv.convert(in().map.get(src));
-      out.map.add(data);
+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 = ModelCostMapMeta.getCostMapResourceId(
+                in().meta.netmap_tags.get(0).rid, in().meta.costType.metric,
+                in().meta.costType.mode);
+
+        // 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()) {
+            ModelCostMapData data = new ModelCostMapData();
+            data.src = src;
+            data.dstCosts = dataConv.convert(in().map.get(src));
+            out.map.add(data);
+        }
+        return out;
     }
-    return out;
-  }
-
-  private String getCostMapResourceId(RFC7285CostMap costMap) {
-    String networkMapRID = costMap.meta.netmap_tags.get(0).rid;
-    String costMetric = costMap.meta.costType.metric;
-    String costMode = costMap.meta.costType.mode;
-    return networkMapRID + "-" + costMetric + "-" + costMode;
-  }
 }
index 351f2aba72dfe53b13ed1ac835f8713c4a6c83c2..796fde7cf29ff8b4c61931cffea4c8d2d312b886 100644 (file)
@@ -29,12 +29,12 @@ public class RFC2ModelCostMapDataConverter
   protected Object _convert() {
     List<ModelDstCosts> dstCostsList = new LinkedList<ModelDstCosts>();
     for (String dst : in().keySet()) {
+      //TODO: Should support different implementations
       ModelDstCosts dstCosts = new ModelDstCosts();
       dstCosts.dst = dst;
-      dstCosts.cost = in().get(dst);
+      dstCosts.costDefault = in().get(dst).toString();
       dstCostsList.add(dstCosts);
     }
     return dstCostsList;
   }
-
 }
index 64ad25528c90997684d70e2361ab9697c6816e99..dfcb148a30d59f06d5a921855702ec72080c6338 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.alto.commons.types.model150404.ModelEndpointPropertyMap;
 import org.opendaylight.alto.commons.types.model150404.ModelEndpointPropertyMeta;
 import org.opendaylight.alto.commons.types.model150404.ModelProperties;
 import org.opendaylight.alto.commons.types.rfc7285.RFC7285EndpointPropertyMap;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285VersionTag;
 
 public class RFC2ModelEndpointPropMapConverter
   extends Converter<RFC7285EndpointPropertyMap, ModelEndpointPropertyMap> {
@@ -46,11 +47,13 @@ public class RFC2ModelEndpointPropMapConverter
     ModelEndpointPropertyMeta endpointPropertyMeta = new ModelEndpointPropertyMeta();
 
     endpointPropertyMeta.dependentVtags = new LinkedList<ModelDependentVtag>();
-    ModelDependentVtag dependentVtag = new ModelDependentVtag();
-    dependentVtag.rid = meta.netmap_tags.get(0).rid;
-    dependentVtag.vTag = meta.netmap_tags.get(0).tag;
+    for (RFC7285VersionTag vtag : meta.netmap_tags) {
+        ModelDependentVtag dependentVtag = new ModelDependentVtag();
+        dependentVtag.rid = vtag.rid;
+        dependentVtag.vTag = vtag.tag;
+        endpointPropertyMeta.dependentVtags.add(dependentVtag);
+    }
 
-    endpointPropertyMeta.dependentVtags.add(dependentVtag);
     return endpointPropertyMeta;
   }
 
@@ -71,5 +74,4 @@ public class RFC2ModelEndpointPropMapConverter
     property.propertyValue = propertyValue;
     return property;
   }
-
 }
index b742bfc809a1d8cd5995b6607d7fa76395c0daf9..b64a945738b8fdbf5aa1b936264622c4f3f84125 100644 (file)
@@ -20,6 +20,11 @@ import java.util.LinkedHashMap;
 import com.fasterxml.jackson.databind.JsonNode;
 
 public class YANGJSON2RFCCostMapConverter extends Converter<JsonNode, RFC7285CostMap> {
+    private static final String NUMERICAL_MODE = "numerical";
+    private static final String ORDINAL_MODE = "ordinal";
+    private static final String ROUTING_COST_METRIC = "routingcost";
+    private static final String HOP_COUNT_METRIC = "hopcount";
+
     public YANGJSON2RFCCostMapConverter() {
     }
 
@@ -40,8 +45,8 @@ public class YANGJSON2RFCCostMapConverter extends Converter<JsonNode, RFC7285Cos
         }
 
         JsonNode cost_type = meta.get("costType");
-        String mode = cost_type.get("costMode").asText();
-        String metric = cost_type.get("costMetric").get("value").asText();
+        String mode = cost_type.get("costMode").asText().toLowerCase();
+        String metric = cost_type.get("costMetric").get("value").asText().toLowerCase();
         cm.meta.costType = new RFC7285CostType(mode, metric);
 
         JsonNode map = node.get("map");
@@ -55,7 +60,8 @@ public class YANGJSON2RFCCostMapConverter extends Converter<JsonNode, RFC7285Cos
 
                 JsonNode cost_node = dst.get("cost");
                 if ((cost_node != null) && (!cost_node.isNull())) {
-                    data.put(dst_pid, cost_node.asText());
+                    Object cost = cost(mode, metric, cost_node.asText());
+                    data.put(dst_pid, cost);
                 }
             }
 
@@ -63,4 +69,19 @@ public class YANGJSON2RFCCostMapConverter extends Converter<JsonNode, RFC7285Cos
         }
         return cm;
     }
+
+    private Object cost(String mode, String metric, String cost) {
+        if (ORDINAL_MODE.equals(mode.toLowerCase())) {
+            return Integer.parseInt(cost);
+        }
+
+        if (NUMERICAL_MODE.equals(mode.toLowerCase())) {
+            if (HOP_COUNT_METRIC.equals(metric.toLowerCase())) {
+                return Integer.parseInt(cost);
+            } else if (ROUTING_COST_METRIC.equals(metric.toLowerCase())) {
+                return Double.parseDouble(cost);
+            }
+        }
+        return cost;
+    }
 }
index c8bd1ba25709bcc561c063333150f4fc4787b3a5..5bc7134b0cf08d8f958fc55600fc58be5eacf3d3 100644 (file)
@@ -20,36 +20,42 @@ import org.opendaylight.yangtools.yang.binding.DataContainer;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-public class ModelCostMapMeta implements Meta  {
-
-  @JsonProperty("alto-service:dependent-vtags")
-  public List<ModelDependentVtag> dependentVtags = new LinkedList<ModelDependentVtag>();
-
-  @JsonProperty("alto-service:cost-type")
-  public ModelCostType costType = new ModelCostType();
-
-  @JsonIgnore
-  @Override
-  public Class<? extends DataContainer> getImplementedInterface() {
-    return Meta.class;
-  }
-
-  @JsonIgnore
-  @Override
-  public List<DependentVtags> getDependentVtags() {
-    return new LinkedList<DependentVtags>(dependentVtags);
-  }
-
-  @JsonIgnore
-  @Override
-  public CostType getCostType() {
-    return costType;
-  }
-
-  @JsonIgnore
-  @Override
-  public <E extends Augmentation<Meta>> E getAugmentation(Class<E> arg0) {
-    return null;
-  }
+public class ModelCostMapMeta implements Meta {
+
+    @JsonProperty("alto-service:dependent-vtags")
+    public List<ModelDependentVtag> dependentVtags = new LinkedList<ModelDependentVtag>();
+
+    @JsonProperty("alto-service:cost-type")
+    public ModelCostType costType = new ModelCostType();
+
+    @JsonIgnore
+    @Override
+    public Class<? extends DataContainer> getImplementedInterface() {
+        return Meta.class;
+    }
+
+    @JsonIgnore
+    @Override
+    public List<DependentVtags> getDependentVtags() {
+        return new LinkedList<DependentVtags>(dependentVtags);
+    }
+
+    @JsonIgnore
+    @Override
+    public CostType getCostType() {
+        return costType;
+    }
+
+    @JsonIgnore
+    @Override
+    public <E extends Augmentation<Meta>> E getAugmentation(Class<E> arg0) {
+        return null;
+    }
+
+    @JsonIgnore
+    public static String getCostMapResourceId(String networkMapRID,
+            String costMetric, String costMode) {
+        return networkMapRID + "-" + costMetric + "-" + costMode;
+    }
 
 }
index 4fe52ec6d4fbb35ac9ed3091800fcee86dc42f89..0aa1e49dcc23745686c274d753ee0551a1dd687e 100644 (file)
@@ -1,13 +1,6 @@
-/*
- * 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.commons.types.model150404;
 
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts2;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.map.DstCosts;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.map.DstCostsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.PidName;
@@ -17,13 +10,19 @@ import org.opendaylight.yangtools.yang.binding.DataContainer;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-public class ModelDstCosts implements DstCosts {
+public class ModelDstCosts implements DstCosts, DstCosts2 {
 
   @JsonProperty("alto-service:dst")
   public String dst = null;
 
-  @JsonProperty("alto-service:cost")
-  public Object cost = null;
+  @JsonProperty("alto-cost-default:cost-default")
+  public String costDefault;
+
+  @JsonIgnore
+  @Override
+  public String getCostDefault() {
+    return costDefault;
+  }
 
   @JsonIgnore
   @Override
@@ -34,7 +33,7 @@ public class ModelDstCosts implements DstCosts {
   @JsonIgnore
   @Override
   public <E extends Augmentation<DstCosts>> E getAugmentation(Class<E> arg0) {
-    return null;
+    return (E) this;
   }
 
   @JsonIgnore
@@ -48,5 +47,4 @@ public class ModelDstCosts implements DstCosts {
   public DstCostsKey getKey() {
     return new DstCostsKey(getDst());
   }
-
 }
index 7535d88428aaa36c042e13d8ce6740d6380d14b9..ae9bcdbc8bb00d6a70b7454a74af1d305e217037 100644 (file)
@@ -12,6 +12,7 @@ import java.util.LinkedList;
 import java.util.List;
 
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.TypedEndpointAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.TypedEndpointAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.property.map.data.EndpointProperties;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.property.map.data.EndpointPropertiesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.property.map.data.endpoint.properties.Properties;
@@ -45,7 +46,7 @@ public class ModelEndpointProperties implements EndpointProperties {
   @JsonIgnore
   @Override
   public TypedEndpointAddress getEndpoint() {
-    return new TypedEndpointAddress(endpoint.toCharArray());
+    return TypedEndpointAddressBuilder.getDefaultInstance(endpoint);
   }
 
   @JsonIgnore
index d4e33b2c58ca304c561eecf7946c56c5871adc31..0a9835cb09950a48f475fd4f666231aeb2d5abbb 100644 (file)
@@ -24,6 +24,28 @@ public class FormatValidator {
     private static final String VALID_TAG_CHARSET = "!-~";
     private static final Pattern VALID_TAG_PATTERN
                             = Pattern.compile("^["+VALID_TAG_CHARSET+"]{1,64}$");
+    private static final String VALID_ADDR_IPV4 = "^ipv4:(([0-9]|[1-9][0-9]|1[0-9][0-9]|"
+                                                    + "2[0-4][0-9]|25[0-5])\\.){3}"
+                                                    + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
+                                                    + "(%[\\p{N}\\p{L}]+)?$";
+    private static final Pattern VALID_ADDR_IPV4_PATTERN
+                            = Pattern.compile(VALID_ADDR_IPV4);
+    private static final String VALID_ADDR_IPV6_1 = "^ipv6:((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
+                                                    + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|"
+                                                    + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
+                                                    + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))"
+                                                    + "(%[\\p{N}\\p{L}]+)?$";
+    private static final Pattern VALID_ADDR_IPV6_1_PATTERN
+                            = Pattern.compile(VALID_ADDR_IPV6_1);
+    private static final String VALID_ADDR_IPV6_2 = "^ipv6:((([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|"
+                                                    + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
+                                                    + "(%.+)?)$";
+    private static final Pattern VALID_ADDR_IPV6_2_PATTERN
+                            = Pattern.compile(VALID_ADDR_IPV6_2);
+    private static final String VALID_OPERATORS = "(gt|lt|ge|le|eq)";
+    private static final Pattern VALID_CONSTRAINTS_PATTERN
+                            = Pattern.compile("^"+VALID_OPERATORS+" [0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$");
+
 
     public static boolean validId(String id) {
         return VALID_ID_PATTERN.matcher(id).matches();
@@ -80,4 +102,24 @@ public class FormatValidator {
     public static boolean validGlobalEndpointProperty(String prop) {
         return (prop.length() <= 32) && validId(prop);
     }
+
+    /**
+     * RFC 7285 section 11.3.2
+     * */
+    public static boolean validFilterConstraint(String constrant) {
+        return VALID_CONSTRAINTS_PATTERN.matcher(constrant).matches();
+    }
+
+    public static boolean validAddressIpv4(String address) {
+        return VALID_ADDR_IPV4_PATTERN.matcher(address).matches();
+    }
+
+    public static boolean validAddressIpv6(String address) {
+        return VALID_ADDR_IPV6_1_PATTERN.matcher(address).matches() &&
+                VALID_ADDR_IPV6_2_PATTERN.matcher(address).matches();
+    }
+
+    public static boolean validEndpointAddress(String address) {
+        return validAddressIpv4(address) || validAddressIpv6(address);
+    }
 }
index 1d7bc5ea903ae0b4d840da954a8fff28433888a4..f03116c1c7cf4e376e24133f7f37544ff2fb7f94 100644 (file)
@@ -38,7 +38,10 @@ public class RFC7285CostMap {
         public RFC7285CostType costType;
 
         @JsonProperty("pids")
-        public RFC7285QueryPairs pids = new RFC7285QueryPairs();
+        public RFC7285QueryPairs pids;
+
+        @JsonProperty("constraints")
+        public List<String> constraints;
     }
 
     @JsonProperty("meta")
index 8507ba630c3afe86b6b5dd7e14c637e801e866e3..487fe46bc2d2a1469bdcaa0a9d263ccf79a189fa 100644 (file)
@@ -37,11 +37,11 @@ public class RFC7285Endpoint {
 
     public static class PropertyRequest {
 
-        @JsonProperty("properties")
-        public List<String> properties = new ArrayList<String>();
+        @JsonProperty(value="properties")
+        public List<String> properties;
 
-        @JsonProperty("endpoints")
-        public List<String> endpoints = new ArrayList<String>();
+        @JsonProperty(value="endpoints")
+        public List<String> endpoints;
     }
 
     public static class PropertyResponse {
index 4db1ea1d18e14f33e275696d8eb8bc80776316f3..a63633d013c332756e57ad693b480dcfe0435cc4 100644 (file)
@@ -12,20 +12,32 @@ import java.util.List;
 import java.util.Map;
 import java.util.LinkedHashMap;
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
 
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
 public class RFC7285IRD {
-
-    public class Meta extends Extensible {
-
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    public class Meta {
         @JsonProperty("default-alto-network-map")
-        public String defaultAltoNetworkMap = "";
+        public String defaultAltoNetworkMap;
 
         @JsonProperty("cost-types")
         public Map<String, RFC7285CostType> costTypes = new LinkedHashMap<String, RFC7285CostType>();
 
     }
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    public class Capability {
+        @JsonProperty("cost-constraints")
+        public Boolean costConstraints;
 
+        @JsonProperty("cost-type-names")
+        public List<String> costTypeNames;
+
+        @JsonProperty("prop-types")
+        public List<String> propTypes;
+    }
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
     public class Entry {
         @JsonProperty("uri")
         public String uri;
@@ -37,7 +49,7 @@ public class RFC7285IRD {
         public String accepts;
 
         @JsonProperty("capabilities")
-        public Map<String, Object> capabilities;
+        public Capability capabilities;
 
         @JsonProperty("uses")
         public List<String> uses;
index da97493cc4e2d44877660882f259745c3e404767..3ff53cb8caea312ce977c85bfcba1205225f3bd2 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.alto.commons.types.rfc7285;
 
 import java.util.LinkedHashMap;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -33,8 +32,9 @@ public class RFC7285NetworkMap {
     public static class Filter {
 
         @JsonProperty("pids")
-        public List<String> pids = new ArrayList<String>();
-
+        public List<String> pids;
+        @JsonProperty("address-types")
+        public List<String> addressTypes;
     }
 
     @JsonProperty("meta")
index 8a00aa54c2fe045be7bb8ae6e86f8e7c093761f6..dbc6f1ed589ebea232fa17995c374ba9990a31b6 100644 (file)
@@ -21,5 +21,4 @@ public class RFC7285QueryPairs {
     @JsonProperty("dsts")
     public List<String> dst = new LinkedList<String>();
 
-}
-
+}
\ No newline at end of file
index 33939e720b3fbcd7e241f3633abdb6de66098e4b..b5acce0f996d3ca8943e44d5a35641f7508612d5 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Collection;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
+import java.util.ArrayList;
 
 import org.junit.Test;
 
@@ -111,7 +112,7 @@ public class TestRFC7285Types {
         RFC7285JSONMapper mapper = new RFC7285JSONMapper();
 
         RFC7285NetworkMap.Filter filter = new RFC7285NetworkMap.Filter();
-
+        filter.pids = new ArrayList<String>();
         filter.pids.add("PID1");
         filter.pids.add("PID2");
 
@@ -199,6 +200,7 @@ public class TestRFC7285Types {
 
         RFC7285CostMap.Filter filter = new RFC7285CostMap.Filter();
         filter.costType = new RFC7285CostType("numerical", "routingcost", "test");
+        filter.pids = new RFC7285QueryPairs();
         filter.pids.src.add("PID1");
         filter.pids.dst.add("PID1");
         filter.pids.dst.add("PID2");
index 429f142fe35406a5318585ba78f38c320ca3694a..f545bb6898be145748c1a29c34444696de664e10 100644 (file)
@@ -23,8 +23,8 @@ public final class $YangModuleInfoImpl implements YangModuleInfo {
     private $YangModuleInfoImpl() {
         Set<YangModuleInfo> set = new HashSet<>();
         set.add(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.$YangModuleInfoImpl.getInstance());
-        set.add(org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.$YangModuleInfoImpl.getInstance());
         set.add(org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.$YangModuleInfoImpl.getInstance());
+        set.add(org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.$YangModuleInfoImpl.getInstance());
         importedModules = ImmutableSet.copyOf(set);
     
         InputStream stream = $YangModuleInfoImpl.class.getResourceAsStream(resourcePath);
index f87df12898f3c566569e7f2a395950f6b5fddcef..ef2ff8293586217b7f9d15522033f05d7217f7cb 100644 (file)
@@ -13,7 +13,29 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev1504
 public class MediaTypeBuilder {
 
     public static MediaType getDefaultInstance(java.lang.String defaultValue) {
-        throw new java.lang.UnsupportedOperationException("Not yet implemented");
+        if ("application/alto-directory+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoDirectory);
+        } else if ("application/alto-networkmap+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoNetworkmap);
+        } else if ("application/alto-networkmapfilter+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoNetworkmapfilter);
+        } else if ("application/alto-costmap+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoCostmap);
+        } else if ("application/alto-costmapfilter+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoCostmapfilter);
+        } else if ("application/alto-endpointprop+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoEndpointprop);
+        } else if ("application/alto-endpointpropparams+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoEndpointpropparams);
+        } else if ("application/alto-endpointcost+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoEndpointcost);
+        } else if ("application/alto-endpointcostparams+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoEndpointcostparams);
+        } else if ("application/alto-error+json".equals(defaultValue)) {
+            return new MediaType(MediaType.Enumeration.AltoError);
+        }
+
+        throw new java.lang.UnsupportedOperationException("Wrong MediaType: "+defaultValue);
     }
 
 }
index 2ce4722da5f5706b2c1974185f48ea672468e155..97f7d027002dcca09084a6d7e07699f197525293 100644 (file)
@@ -11,7 +11,14 @@ module alto-cost-default {
 
     augment "/alto-restconf:endpoint-cost-service/alto-restconf:output/alto-restconf:endpoint-cost-service/alto-restconf:endpoint-cost-map/alto-restconf:dst-costs" {
         leaf cost-default {
-            type int32;
+            type string;
         }
     }
+
+    augment "/alto-restconf:resources/alto-restconf:cost-maps/alto-restconf:cost-map/alto-restconf:map/alto-restconf:dst-costs" {
+        leaf cost-default {
+            type string;
+        }
+    }
+
 }
index 0427d2d544011a4adad368139f0f6ef2e6121427..6988f01e1570f7934b75a4a504b74fc82422ec78 100755 (executable)
@@ -103,9 +103,9 @@ module alto-service-types {
             + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
             + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
             + '(%[\p{N}\p{L}]+)?';
-      pattern 'ipv6:(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+      pattern 'ipv6:((([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
             + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
-            + '(%.+)?';
+            + '(%.+)?)';
     }
   }
 
@@ -441,7 +441,7 @@ module alto-service-types {
 
   typedef constraint {
     type string {
-      pattern "(gt|ge|lt|le|eq) [0-9]+";
+      pattern "(gt|ge|lt|le|eq) [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?";
     }
     description
       "RFC7285 Sec. 11.3.2.3. The second part must be in the" +
index 1bf8b00e3a5cd7aa7305bbd641e2ef2d34bf00d6..47a96f8b8b793d9f1b85a24fb9d9b4f49d091b5b 100644 (file)
       <plugin>
         <groupId>org.codehaus.enunciate</groupId>
         <artifactId>maven-enunciate-plugin</artifactId>
+        <dependencies>
+          <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal</artifactId>
+            <version>${sal.version}</version>
+          </dependency>
+        </dependencies>
       </plugin>
 
       <plugin>
               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.sal.utils,
+              org.opendaylight.controller.sal.authorization,
+              org.opendaylight.controller.sal.packet.address,
               javax.ws.rs,
               javax.ws.rs.core,
+              javax.ws.rs.ext,
               javax.xml.bind.annotation,
               javax.xml.bind,
+              javax.xml.ws.http,
+              javax.servlet.http,
               org.slf4j,
               org.apache.catalina.filters,
-              !org.codehaus.enunciate.jaxrs,
+              com.fasterxml.jackson.jaxrs.base,
+              com.fasterxml.jackson.jaxrs.json,
+              com.fasterxml.jackson.core,
+              com.fasterxml.jackson.databind,
+              !org.codehaus.enunciate.jaxrs
             </Import-Package>
             <Web-ContextPath>/controller/nb/v2/alto</Web-ContextPath>
           </instructions>
       <artifactId>com.sun.jersey.jersey-servlet</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>commons.northbound</artifactId>
+      <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>
     </dependency>
 
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-databind</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-core</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>alto-model</artifactId>
index 87ff4ad85aa5ef4428f93569af286397fefe05f8..1596adff90537940f5d449ac2f5aaa96a6dd6056 100644 (file)
       <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>org.opendaylight.controller</groupId>
       <artifactId>config-api</artifactId>
index 071f252b9d44ece80678012e05484431321a970a..cc016e8d12651cc2a6ea2f6cce631c3b29b9d4e3 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.alto.provider;
 
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -18,8 +19,11 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
-import java.util.logging.Level;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+
+import org.opendaylight.alto.commons.helper.NetworkMapIpPrefixHelper;
+import org.opendaylight.alto.commons.types.model150404.ModelCostMapMeta;
 import org.opendaylight.controller.config.yang.config.alto_provider.impl.AltoProviderRuntimeMXBean;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
@@ -28,6 +32,9 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts2;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.AltoServiceService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.EndpointCostServiceInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.EndpointCostServiceOutput;
@@ -48,10 +55,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cos
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.MetaBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.endpoint.cost.map.DstCosts;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.endpoint.cost.map.DstCostsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.Constraint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.CostMaps;
+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.cost.maps.CostMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.cost.maps.CostMapKey;
+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.CostMetric;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.CostMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.PidName;
+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.TypedEndpointAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.ird.meta.DefaultAltoNetworkMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.host.AttachmentPoints;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -62,8 +78,6 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts1Builder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -83,28 +97,38 @@ import edu.uci.ics.jung.graph.Graph;
 import edu.uci.ics.jung.graph.SparseMultigraph;
 import edu.uci.ics.jung.graph.util.EdgeType;
 
-public class AltoProvider implements
-            AltoServiceService, DataChangeListener,
-            AltoProviderRuntimeMXBean, AutoCloseable {
+public class AltoProvider implements AltoServiceService, DataChangeListener,
+        AltoProviderRuntimeMXBean, AutoCloseable {
 
-    private static final Logger log = LoggerFactory.getLogger(AltoProvider.class);
+    private static final Logger log = LoggerFactory
+            .getLogger(AltoProvider.class);
 
     private ListenerRegistration<DataChangeListener> hostNodeListerRegistration;
 
     private ListenerRegistration<DataChangeListener> linkListerRegistration;
 
     private ListenerRegistration<DataChangeListener> topologyListerRegistration;
+    private ListenerRegistration<DataChangeListener> defaultNetworkMapperRegistration;
+    private NetworkMapIpPrefixHelper ipHelper = new NetworkMapIpPrefixHelper();
+
     private Map<String, String> ipSwitchIdMap = null;
     Graph<NodeId, Link> networkGraph = null;
     Set<String> linkAdded = null;
     DijkstraShortestPath<NodeId, Link> shortestPath = null;
     private AtomicBoolean networkGraphFlag;
-    public static final InstanceIdentifier<Resources> ALTO_IID
-                        = InstanceIdentifier.builder(Resources.class).build();
+    public static final InstanceIdentifier<Resources> ALTO_IID = InstanceIdentifier
+            .builder(Resources.class).build();
 
     private DataBroker dataProvider;
     private final ExecutorService executor;
 
+    private InstanceIdentifier<DefaultAltoNetworkMap> DEFAULT_NETWORK_MAP_IID = InstanceIdentifier
+            .builder(Resources.class)
+            .child(IRD.class)
+            .child(org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.ird.Meta.class)
+            .child(DefaultAltoNetworkMap.class).build();
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     public AltoProvider() {
         this.networkGraph = new SparseMultigraph<>();
         this.shortestPath = new DijkstraShortestPath(this.networkGraph);
@@ -119,7 +143,21 @@ public class AltoProvider implements
         log.info(this.getClass().getName() + " data provider initiated");
     }
 
+    private NetworkMap readNetworkMap(ResourceId rid)
+            throws InterruptedException, ExecutionException {
+        NetworkMapKey key = new NetworkMapKey(rid);
+        InstanceIdentifier<NetworkMap> iid = InstanceIdentifier
+                .builder(Resources.class).child(NetworkMaps.class)
+                .child(NetworkMap.class, key).build();
+        return readDataFromConfiguration(iid);
+    }
+
     public void registerAsDataChangeListener() {
+        this.defaultNetworkMapperRegistration = dataProvider
+                .registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+                        this.DEFAULT_NETWORK_MAP_IID, this,
+                        DataChangeScope.BASE);
+
         InstanceIdentifier<HostNode> hostNodes = InstanceIdentifier
                 .builder(NetworkTopology.class)//
                 .child(Topology.class,
@@ -139,12 +177,13 @@ public class AltoProvider implements
                 DataChangeScope.BASE);
 
         InstanceIdentifier<Topology> topology = InstanceIdentifier
-                .builder(NetworkTopology.class)//
+                .builder(NetworkTopology.class)
+                //
                 .child(Topology.class,
                         new TopologyKey(new TopologyId("flow:1"))).build();
-                this.topologyListerRegistration = dataProvider.registerDataChangeListener(
-                LogicalDatastoreType.OPERATIONAL, topology, this,
-                DataChangeScope.BASE);
+        this.topologyListerRegistration = dataProvider
+                .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                        topology, this, DataChangeScope.BASE);
 
         ReadOnlyTransaction newReadOnlyTransaction = dataProvider
                 .newReadOnlyTransaction();
@@ -152,7 +191,7 @@ public class AltoProvider implements
         ListenableFuture<Optional<Topology>> dataFuture = newReadOnlyTransaction
                 .read(LogicalDatastoreType.OPERATIONAL, topology);
         try {
-            Topology get = dataFuture.get().get();
+            dataFuture.get().get();
         } catch (InterruptedException | ExecutionException ex) {
             java.util.logging.Logger.getLogger(AltoProvider.class.getName())
                     .log(Level.SEVERE, null, ex);
@@ -181,7 +220,7 @@ public class AltoProvider implements
 
         if (this.networkGraph == null) {
             this.networkGraph = new SparseMultigraph<>();
-                        networkGraphFlag.set(true);
+            networkGraphFlag.set(true);
         }
 
         for (Link link : links) {
@@ -194,7 +233,7 @@ public class AltoProvider implements
             this.networkGraph.addVertex(destinationNodeId);
             this.networkGraph.addEdge(link, sourceNodeId, destinationNodeId,
                     EdgeType.UNDIRECTED);
-                        networkGraphFlag.set(true);
+            networkGraphFlag.set(true);
         }
 
     }
@@ -219,36 +258,30 @@ public class AltoProvider implements
 
     public void processTopology(Topology topology) {
         List<Node> nodeList = null;
-                if ((nodeList = topology.getNode()) != null) {
+        if ((nodeList = topology.getNode()) != null) {
             for (int i = 0; i < nodeList.size(); ++i) {
-            Node node = nodeList.get(i);
-            HostNode hostNode = node.getAugmentation(HostNode.class);
-            log.info("process node "+i+hostNode);
-            processNode(hostNode);
+                Node node = nodeList.get(i);
+                HostNode hostNode = node.getAugmentation(HostNode.class);
+                log.info("process node " + i + hostNode);
+                processNode(hostNode);
             }
             List<Link> linkList = topology.getLink();
             addLinks(linkList);
-                }
+        }
     }
 
     private void deleteHostNode(HostNode hostNode) {
-            List<AttachmentPoints> attachmentPoints = hostNode
-                        .getAttachmentPoints();
-
-            TpId tpId = attachmentPoints.get(0).getTpId();
-            String tpIdString = tpId.getValue();
-
-            String ipv4String = hostNode.getAddresses().get(0).getIp()
-                    .getIpv4Address().getValue();
-
-            this.ipSwitchIdMap.remove(ipv4String);
+        String ipv4String = hostNode.getAddresses().get(0).getIp()
+                .getIpv4Address().getValue();
+        this.ipSwitchIdMap.remove(ipv4String);
     }
 
     private void processNode(HostNode hostNode) {
-                if (this.networkGraph==null) {
-                      this.networkGraph = new SparseMultigraph<>();
-                }
-        if(hostNode==null)return;
+        if (this.networkGraph == null) {
+            this.networkGraph = new SparseMultigraph<>();
+        }
+        if (hostNode == null)
+            return;
         List<AttachmentPoints> attachmentPoints = hostNode
                 .getAttachmentPoints();
 
@@ -265,7 +298,7 @@ public class AltoProvider implements
     @Override
     public void onDataChanged(
             final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
-                log.info("in Data Changed");
+        log.info("in Data Changed");
         if (change == null) {
             log.info("In onDataChanged: No processing done as change even is null.");
             return;
@@ -279,52 +312,61 @@ public class AltoProvider implements
         Set<InstanceIdentifier<?>> deletedData = change.getRemovedPaths();
 
         for (InstanceIdentifier<?> iid : deletedData) {
-                        log.info("delete Data");
+            log.info("delete Data");
             if (iid.getTargetType().equals(HostNode.class)) {
-                                log.info("delete hostnode");
+                log.info("delete hostnode");
                 HostNode node = ((HostNode) originalData.get(iid));
                 deleteHostNode(node);
             } else if (iid.getTargetType().equals(Link.class)) {
-                                log.info("delete edge");
-                        String linkAddedKey = null;
-                                Link link = (Link) originalData.get(iid);
-                        if (link.getDestination().getDestTp().hashCode() > link.getSource()
-                        .getSourceTp().hashCode()) {
-                        linkAddedKey = link.getSource().getSourceTp().getValue()
-                    + link.getDestination().getDestTp().getValue();
-                        } else {
-                        linkAddedKey = link.getDestination().getDestTp().getValue()
-                    + link.getSource().getSourceTp().getValue();
-                        }
-                        if (linkAdded.contains(linkAddedKey)) {
-                            linkAdded.remove(linkAddedKey);
-                        }
+                log.info("delete edge");
+                String linkAddedKey = null;
+                Link link = (Link) originalData.get(iid);
+                if (link.getDestination().getDestTp().hashCode() > link
+                        .getSource().getSourceTp().hashCode()) {
+                    linkAddedKey = link.getSource().getSourceTp().getValue()
+                            + link.getDestination().getDestTp().getValue();
+                } else {
+                    linkAddedKey = link.getDestination().getDestTp().getValue()
+                            + link.getSource().getSourceTp().getValue();
+                }
+                if (linkAdded.contains(linkAddedKey)) {
+                    linkAdded.remove(linkAddedKey);
+                }
                 this.networkGraph.removeEdge((Link) originalData.get(iid));
-                                networkGraphFlag.set(true);
+                networkGraphFlag.set(true);
 
+            } else if (iid.getTargetType().equals(DefaultAltoNetworkMap.class)) {
+                ipHelper.clear();
             }
         }
 
         for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : updatedData
                 .entrySet()) {
-
-            InstanceIdentifier<?> iiD = entrySet.getKey();
             final DataObject dataObject = entrySet.getValue();
             if (dataObject instanceof HostNode) {
-                                log.info("update hostnode data");
+                log.info("update hostnode data");
                 processNode((HostNode) dataObject);
+            } else if (dataObject instanceof DefaultAltoNetworkMap) {
+                try {
+                    DefaultAltoNetworkMap defaultMap = (DefaultAltoNetworkMap) dataObject;
+                    NetworkMap networkMap = readNetworkMap(defaultMap
+                            .getResourceId());
+                    ipHelper.update(networkMap);
+                } catch (InterruptedException | ExecutionException
+                        | UnknownHostException e) {
+                    e.printStackTrace();
+                }
             }
         }
 
         for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : createdData
                 .entrySet()) {
-            InstanceIdentifier<?> iiD = entrySet.getKey();
             final DataObject dataObject = entrySet.getValue();
             if (dataObject instanceof HostNode) {
-                                log.info("update HostNode");
+                log.info("update HostNode");
                 processNode((HostNode) dataObject);
             } else if (dataObject instanceof Link) {
-                                log.info("update link");
+                log.info("update link");
                 Link link = (Link) dataObject;
                 if (!linkAlreadyAdded(link)) {
                     NodeId sourceNodeId = link.getSource().getSourceNode();
@@ -332,10 +374,21 @@ public class AltoProvider implements
                             .getDestNode();
                     this.networkGraph.addVertex(sourceNodeId);
                     this.networkGraph.addVertex(destinationNodeId);
-                    this.networkGraph.addEdge(link, sourceNodeId, destinationNodeId,
-                            EdgeType.UNDIRECTED);
-                                        log.info("update link in networkGraph");
-                                        networkGraphFlag.set(true);
+                    this.networkGraph.addEdge(link, sourceNodeId,
+                            destinationNodeId, EdgeType.UNDIRECTED);
+                    log.info("update link in networkGraph");
+                    networkGraphFlag.set(true);
+                }
+            } else if (dataObject instanceof DefaultAltoNetworkMap) {
+                try {
+                    DefaultAltoNetworkMap defaultMap = (DefaultAltoNetworkMap) dataObject;
+                    NetworkMap networkMap = readNetworkMap(defaultMap
+                            .getResourceId());
+                    ipHelper.update(networkMap);
+                } catch (InterruptedException | ExecutionException
+                        | UnknownHostException e) {
+                    e.printStackTrace();
+                    ipHelper.clear();
                 }
             }
         }
@@ -343,11 +396,13 @@ public class AltoProvider implements
 
     }
 
-    public List<EndpointCostMap> hopcountNumerical(List<TypedEndpointAddress> srcs, List<TypedEndpointAddress> dsts) {
-                if (networkGraphFlag.get()) {
-                    shortestPath = new DijkstraShortestPath(this.networkGraph);
-                    networkGraphFlag.set(false);
-                }
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public List<EndpointCostMap> hopcountNumerical(
+            List<TypedEndpointAddress> srcs, List<TypedEndpointAddress> dsts) {
+        if (networkGraphFlag.get()) {
+            shortestPath = new DijkstraShortestPath(this.networkGraph);
+            networkGraphFlag.set(false);
+        }
         List<EndpointCostMap> result = new ArrayList<EndpointCostMap>();
         for (int i = 0; i < srcs.size(); ++i) {
             TypedEndpointAddress teaSrc = srcs.get(i);
@@ -369,13 +424,14 @@ public class AltoProvider implements
                 NodeId srcNodeId = new NodeId(swSrcId);
                 NodeId dstNodeId = new NodeId(swDstId);
                 Number number = shortestPath.getDistance(srcNodeId, dstNodeId);
-                                DstCosts1 dst1 = null;
-                                if (number!=null) {
-                    dst1 = new DstCosts1Builder().setCostDefault(number.intValue()).build();
-                                }
-                                else {
-                                    dst1 = new DstCosts1Builder().setCostDefault(Integer.MAX_VALUE).build();
-                                }
+                DstCosts1 dst1 = null;
+                if (number != null) {
+                    dst1 = new DstCosts1Builder().setCostDefault(
+                            Integer.toString(number.intValue())).build();
+                } else {
+                    dst1 = new DstCosts1Builder().setCostDefault(
+                            Integer.toString(Integer.MAX_VALUE)).build();
+                }
                 DstCosts dstCost = new DstCostsBuilder()
                         .addAugmentation(DstCosts1.class, dst1).setDst(teaDst)
                         .build();
@@ -392,71 +448,242 @@ public class AltoProvider implements
     @Override
     public Future<RpcResult<EndpointCostServiceOutput>> endpointCostService(
             EndpointCostServiceInput input) {
+        RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder = null;
+        if (input.getCostType() == null) {
+            endpointCostServiceBuilder = RpcResultBuilder
+                    .<EndpointCostServiceOutput> failed().withError(
+                            ErrorType.APPLICATION, "Invalid cost-type value ",
+                            "Argument can not be null.");
+        }
+
+        if (input.getEndpoints() == null) {
+            endpointCostServiceBuilder = RpcResultBuilder
+                    .<EndpointCostServiceOutput> failed().withError(
+                            ErrorType.APPLICATION, "Invalid endpoints value ",
+                            "Argument can not be null.");
+        }
 
-        CostType costTypeInput = null;
-        List<Constraint> constraintsInput = null;
-        Endpoints endpointsInput = null;
+        return hosttrackerNumericalHopCountImplementation(input, endpointCostServiceBuilder);
+    }
 
-        RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder = null;
+    public ListenableFuture<RpcResult<EndpointCostServiceOutput>> interopECSImplementation(
+            EndpointCostServiceInput input,
+            RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder) {
+        if (!ipHelper.initiated()) {
+            return Futures.immediateFuture(RpcResultBuilder
+                    .<EndpointCostServiceOutput> failed()
+                    .withError(ErrorType.APPLICATION, "Default Map Error",
+                            "Failed to parse default network map.").build());
+        }
+
+        Endpoints endpoints = input.getEndpoints();
+        CostMap costMap = getDefaultCostMap(input.getCostType());
+        if (costMap == null) {
+            return Futures.immediateFuture(RpcResultBuilder
+                    .<EndpointCostServiceOutput> failed()
+                    .withError(ErrorType.APPLICATION, "Cost Map Error",
+                            "Failed to read data from cost map.").build());
+        }
 
         EndpointCostServiceOutput output = null;
+        org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostType eCostType = new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostTypeBuilder()
+                .setCostMetric(input.getCostType().getCostMetric())
+                .setCostMode(input.getCostType().getCostMode()).build();
+
+        Meta meta = new MetaBuilder().setCostType(eCostType).build();
+        List<TypedEndpointAddress> srcs = endpoints.getSrcs();
+        List<TypedEndpointAddress> dsts = endpoints.getDsts();
+        List<EndpointCostMap> ecmList = getEndpointCostListFromCostMap(
+                ipHelper, costMap, srcs, dsts);
+        EndpointCostService ecs = new EndpointCostServiceBuilder()
+                .setMeta(meta).setEndpointCostMap(ecmList).build();
+
+        if ((output = new EndpointCostServiceOutputBuilder()
+                .setEndpointCostService(ecs).build()) != null) {
+            endpointCostServiceBuilder = RpcResultBuilder.success(output);
+        } else {
+            endpointCostServiceBuilder = RpcResultBuilder
+                    .<EndpointCostServiceOutput> failed().withError(
+                            ErrorType.APPLICATION, "Invalid output value",
+                            "Output is null.");
+        }
+
+        return Futures.immediateFuture(endpointCostServiceBuilder.build());
+    }
 
-        if ((costTypeInput = input.getCostType()) == null) {
-            endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid cost-type value ", "Argument can not be null.");
+    private CostMap getDefaultCostMap(CostType costType) {
+        CostMap costMap = null;
+        try {
+            String costMapRid = ModelCostMapMeta.getCostMapResourceId(
+                    readDefaultNetworkMapId().getValue(), costType
+                            .getCostMetric().getString(), costType
+                            .getCostMode().name().toLowerCase());
+            InstanceIdentifier<CostMap> costMapNode = costMapIID(new ResourceId(
+                    costMapRid));
+            costMap = readDataFromConfiguration(costMapNode);
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
         }
-        else {
-            if ((endpointsInput = input.getEndpoints()) == null) {
-                endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "Argument can not be null.");
-            }
-            else {
-                Endpoints endpoints = input.getEndpoints();
-                List<TypedEndpointAddress> srcs = endpoints.getSrcs();
-                List<TypedEndpointAddress> dsts = endpoints.getDsts();
-                boolean srcDstFoundFlag = true;
-                for (int i = 0; i < srcs.size(); ++i) {
-                    TypedEndpointAddress teaSrc = srcs.get(i);
-                    String ipv4SrcString = teaSrc.getTypedIpv4Address().getValue()
-                            .substring(5);
-                    if (this.ipSwitchIdMap.get(ipv4SrcString) == null) {
-                        endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "src IP:"+ipv4SrcString+ " can not be found. Or Topology has not been built.");
-                        srcDstFoundFlag = false;
-                        return Futures.immediateFuture(endpointCostServiceBuilder.build());
-                    }
+        return costMap;
+    }
+
+    private ResourceId readDefaultNetworkMapId() throws InterruptedException,
+            ExecutionException {
+        return readDataFromConfiguration(this.DEFAULT_NETWORK_MAP_IID)
+                .getResourceId();
+    }
+
+    private InstanceIdentifier<CostMap> costMapIID(ResourceId rid) {
+        return InstanceIdentifier.builder(Resources.class)
+                .child(CostMaps.class)
+                .child(CostMap.class, new CostMapKey(rid)).build();
+    }
+
+    public List<EndpointCostMap> getEndpointCostListFromCostMap(
+            NetworkMapIpPrefixHelper ipHelper, CostMap costMap,
+            List<TypedEndpointAddress> srcs, List<TypedEndpointAddress> dsts) {
+        Map<TypedEndpointAddress, PidName> srcPids = ipHelper
+                .getPIDsByEndpointAddresses(srcs);
+        Map<TypedEndpointAddress, PidName> dstPids = ipHelper
+                .getPIDsByEndpointAddresses(dsts);
+        Map<PidName, Map<PidName, DstCosts2>> costMaps = costMapListToMap(costMap
+                .getMap());
+
+        List<EndpointCostMap> ecmList = new ArrayList<EndpointCostMap>();
+        for (TypedEndpointAddress src : srcs) {
+            List<DstCosts> dstList = new ArrayList<DstCosts>();
+            for (TypedEndpointAddress dst : dsts) {
+                PidName srcPid = srcPids.get(src);
+                PidName dstPid = dstPids.get(dst);
+                String cost = getCostDefault(srcPid, dstPid, costMaps);
+                if (cost != null) {
+                    DstCosts1 dstCost1 = new DstCosts1Builder().setCostDefault(
+                            cost).build();
+                    DstCosts dstCosts = new DstCostsBuilder()
+                            .setDst(dst)
+                            .setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.endpoint.cost.map.DstCostsKey(
+                                    dst))
+                            .addAugmentation(DstCosts1.class, dstCost1).build();
+                    dstList.add(dstCosts);
                 }
-                for (int j = 0; j < dsts.size(); ++j) {
-                    TypedEndpointAddress teaDst = dsts.get(j);
-                    String ipv4DstString = teaDst.getTypedIpv4Address().getValue()
-                            .substring(5);
-                    if (this.ipSwitchIdMap.get(ipv4DstString) == null) {
-                        endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "dst IP:"+ipv4DstString+" can not be found. Or Topology has not been built.");
-                        srcDstFoundFlag = false;
-                        return Futures.immediateFuture(endpointCostServiceBuilder.build());
-                    }
+            }
+            if (dstList.size() > 0) {
+                ecmList.add(new EndpointCostMapBuilder().setDstCosts(dstList)
+                    .setKey(new EndpointCostMapKey(src)).setSrc(src).build());
+            }
+        }
+        return ecmList;
+    }
+
+    private String getCostDefault(PidName srcPid, PidName dstPid,
+            Map<PidName, Map<PidName, DstCosts2>> costMaps) {
+        if (srcPid != null && dstPid != null) {
+            Map<PidName, DstCosts2> dstMap = costMaps.get(srcPid);
+            if (dstMap != null) {
+                DstCosts2 dstCost2 = dstMap.get(dstPid);
+                if (dstCost2 != null) {
+                    return dstCost2.getCostDefault();
                 }
-                CostMetric costMetric = costTypeInput.getCostMetric();
-                CostMode costMode = costTypeInput.getCostMode();
-                if (srcDstFoundFlag && costMode.equals(CostMode.Numerical) && (costMetric.getEnumeration() == CostMetric.Enumeration.Hopcount || costMetric.getString().equals("hopcount"))){
-                    org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostType costType = new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostTypeBuilder()
-                    .setCostMetric(costMetric)
-                    .setCostMode(costMode).build();
-                    Meta meta = new MetaBuilder().setCostType(costType).build();
-                    List<EndpointCostMap> ecmList = hopcountNumerical(srcs, dsts);
-                    EndpointCostService ecs = new EndpointCostServiceBuilder().setMeta(meta).setEndpointCostMap(ecmList).build();
-
-                    if ((output = new EndpointCostServiceOutputBuilder().setEndpointCostService(ecs).build()) != null) {
-                        endpointCostServiceBuilder = RpcResultBuilder.success(output);
-                    }
-                    else {
-                        endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid output value", "Output is null.");
-                    }
-                    return Futures.immediateFuture(endpointCostServiceBuilder.build());
+            }
+        }
+        return null;
+    }
 
+    private Map<PidName, Map<PidName, DstCosts2>> costMapListToMap(
+            List<org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Map> costMaps) {
+        Map<PidName, Map<PidName, DstCosts2>> resultCostMaps = new HashMap<PidName, Map<PidName, DstCosts2>>();
+        for (org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Map costMap : costMaps) {
+            Map<PidName, DstCosts2> resultCostMap = new HashMap<PidName, DstCosts2>();
+            for (org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.map.DstCosts dstCosts : costMap
+                    .getDstCosts()) {
+                DstCosts2 cost = dstCosts.getAugmentation(DstCosts2.class);
+                if (cost != null) {
+                    resultCostMap.put(dstCosts.getDst(), cost);
                 }
+            }
+            resultCostMaps.put(costMap.getSrc(), resultCostMap);
+        }
+        return resultCostMaps;
+    }
+
+    @SuppressWarnings("unused")
+    private ListenableFuture<RpcResult<EndpointCostServiceOutput>> hosttrackerNumericalHopCountImplementation(
+            EndpointCostServiceInput input,
+            RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder) {
+        Endpoints endpoints = input.getEndpoints();
+        List<TypedEndpointAddress> srcs = endpoints.getSrcs();
+        List<TypedEndpointAddress> dsts = endpoints.getDsts();
+        CostType costTypeInput = input.getCostType();
+        EndpointCostServiceOutput output = null;
+
+        boolean srcDstFoundFlag = true;
+        for (int i = 0; i < srcs.size(); ++i) {
+            TypedEndpointAddress teaSrc = srcs.get(i);
+            String ipv4SrcString = teaSrc.getTypedIpv4Address().getValue()
+                    .substring(5);
+            if (this.ipSwitchIdMap.get(ipv4SrcString) == null) {
+                endpointCostServiceBuilder = RpcResultBuilder
+                        .<EndpointCostServiceOutput> failed()
+                        .withError(
+                                ErrorType.APPLICATION,
+                                "Invalid endpoints value ",
+                                "src IP:"
+                                        + ipv4SrcString
+                                        + " can not be found. Or Topology has not been built.");
+                srcDstFoundFlag = false;
+                return Futures.immediateFuture(endpointCostServiceBuilder
+                        .build());
+            }
+        }
+
+        for (int j = 0; j < dsts.size(); ++j) {
+            TypedEndpointAddress teaDst = dsts.get(j);
+            String ipv4DstString = teaDst.getTypedIpv4Address().getValue()
+                    .substring(5);
+            if (this.ipSwitchIdMap.get(ipv4DstString) == null) {
+                endpointCostServiceBuilder = RpcResultBuilder
+                        .<EndpointCostServiceOutput> failed()
+                        .withError(
+                                ErrorType.APPLICATION,
+                                "Invalid endpoints value ",
+                                "dst IP:"
+                                        + ipv4DstString
+                                        + " can not be found. Or Topology has not been built.");
+                srcDstFoundFlag = false;
+                return Futures.immediateFuture(endpointCostServiceBuilder
+                        .build());
+            }
+        }
 
+        CostMetric costMetric = costTypeInput.getCostMetric();
+        CostMode costMode = costTypeInput.getCostMode();
+        if (srcDstFoundFlag
+                && costMode.equals(CostMode.Numerical)
+                && (costMetric.getEnumeration() == CostMetric.Enumeration.Hopcount || costMetric
+                        .getString().equals("hopcount"))) {
+            org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostType costType = new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostTypeBuilder()
+                    .setCostMetric(costMetric).setCostMode(costMode).build();
+            Meta meta = new MetaBuilder().setCostType(costType).build();
+            List<EndpointCostMap> ecmList = hopcountNumerical(srcs, dsts);
+            EndpointCostService ecs = new EndpointCostServiceBuilder()
+                    .setMeta(meta).setEndpointCostMap(ecmList).build();
+
+            if ((output = new EndpointCostServiceOutputBuilder()
+                    .setEndpointCostService(ecs).build()) != null) {
+                endpointCostServiceBuilder = RpcResultBuilder.success(output);
+            } else {
+                endpointCostServiceBuilder = RpcResultBuilder
+                        .<EndpointCostServiceOutput> failed().withError(
+                                ErrorType.APPLICATION, "Invalid output value",
+                                "Output is null.");
             }
+            return Futures.immediateFuture(endpointCostServiceBuilder.build());
         }
-        return Futures.immediateFuture(RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid output value", "Output is null.").build());
 
+        return Futures.immediateFuture(RpcResultBuilder
+                .<EndpointCostServiceOutput> failed()
+                .withError(ErrorType.APPLICATION, "Invalid output value",
+                        "Output is null.").build());
     }
 
     @Override
@@ -478,6 +705,8 @@ public class AltoProvider implements
         this.hostNodeListerRegistration.close();
         this.linkListerRegistration.close();
         this.ipSwitchIdMap.clear();
+        this.defaultNetworkMapperRegistration.close();
+        this.topologyListerRegistration.close();
         executor.shutdown();
         if (dataProvider != null) {
             WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
@@ -488,11 +717,23 @@ public class AltoProvider implements
                     log.debug("Delete ALTO commit result: " + result);
                 }
 
-            @Override
-            public void onFailure(final Throwable t) {
-                log.error("Delete of ALTO failed", t);
-            }
+                @Override
+                public void onFailure(final Throwable t) {
+                    log.error("Delete of ALTO failed", t);
+                }
             });
         }
     }
+
+    private <T extends DataObject> T readDataFromConfiguration(
+            InstanceIdentifier<T> iid) throws InterruptedException,
+            ExecutionException {
+        ReadOnlyTransaction tx = this.dataProvider.newReadOnlyTransaction();
+        Optional<T> optional = tx.read(LogicalDatastoreType.CONFIGURATION, iid)
+                .get();
+        if (optional.isPresent()) {
+            return optional.get();
+        }
+        return null;
+    }
 }
index 78fbc8bf1236d7bbfdd6a519838b24c365de13df..4f2c3cadd0a88f0a1b941b17cb2a00ca2b9b1150 100644 (file)
@@ -22,9 +22,9 @@ public final class $YangModuleInfoImpl implements YangModuleInfo {
 
     private $YangModuleInfoImpl() {
         Set<YangModuleInfo> set = new HashSet<>();
+        set.add(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.rpc.context.rev130617.$YangModuleInfoImpl.getInstance());
         set.add(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.binding.rev131028.$YangModuleInfoImpl.getInstance());
         set.add(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.$YangModuleInfoImpl.getInstance());
-        set.add(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.rpc.context.rev130617.$YangModuleInfoImpl.getInstance());
         importedModules = ImmutableSet.copyOf(set);
     
         InputStream stream = $YangModuleInfoImpl.class.getResourceAsStream(resourcePath);
index 9cccca242e971e76c497e6bcc7f1afade6828b21..e71b24308eb1487b5e678b2e2231a0ebe49b1600 100644 (file)
@@ -151,7 +151,7 @@ public class AltoProviderTest {
       List<TypedEndpointAddress> teaList2 = new ArrayList<TypedEndpointAddress>();
       teaList2.add(tea2);
 
-      DstCosts1 dc1 = new DstCosts1Builder().setCostDefault(1).build();
+      DstCosts1 dc1 = new DstCosts1Builder().setCostDefault(Integer.toString(1)).build();
       DstCosts dc = new DstCostsBuilder().setDst(tea2).addAugmentation(DstCosts1.class, dc1).build();
 
       List<DstCosts> dcList = new ArrayList<DstCosts>();
index 9d01c24565def520d09aaaf9c2df92e07ef6a96b..da5c57007c3737332503fddba62f57ee350d76ac 100644 (file)
@@ -31,6 +31,15 @@ module simple-alto-adsal-impl {
         case simple-alto-adsal-impl {
             when "/config:modules/config:module/config:type = 'simple-alto-adsal-impl'";
 
+            container rpc-registry {
+                uses config:service-ref {
+                    refine type {
+                        mandatory true;
+                        config:required-identity mdsal:binding-rpc-registry;
+                    }
+                }
+            }
+
             container data-broker {
                 uses config:service-ref {
                     refine type {
diff --git a/pom.xml b/pom.xml
index ad331d185af348829922e84af5a3cd8ea2e6a275..9525443eb929a29086af5e868641aa7737788bca 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>sal-common-util</artifactId>
         <version>${mdsal.version}</version>
       </dependency>
+      <dependency>
+        <groupId>com.googlecode.concurrent-trees</groupId>
+        <artifactId>concurrent-trees</artifactId>
+        <version>2.4.0</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>