Fix Metadata Eid processing for LISP
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / util / ConfigManagerHelper.java
index ed79a352324cf6c66a895e5a0f6df9bbdc8fee94..67ad968dac4b06f685a929a355da9403a3794081 100644 (file)
@@ -8,6 +8,11 @@
 
 package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -56,9 +61,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.MacAddressType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.HmacKeyType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.hmac.key.grouping.HmacKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev171013.HmacKeyType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev171013.dp.subtable.grouping.local.mappings.local.mapping.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev171013.hmac.key.grouping.HmacKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.Routing;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.RoutingBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
@@ -68,15 +73,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-
-
-/**
- * Created by Shakib Ahmed on 3/31/17.
- */
 public class ConfigManagerHelper {
     private static final Logger LOG = LoggerFactory.getLogger(ConfigManagerHelper.class);
 
@@ -86,72 +82,6 @@ public class ConfigManagerHelper {
         this.mountedDataBrokerProvider = mountedDataBrokerProvider;
     }
 
-    public EndpointHost getEndpointHostInformation(AddressEndpointWithLocation addressEpWithLoc) {
-        DataBroker endpointHostDataBroker = getPotentialExternalDataBroker(addressEpWithLoc).get();
-        String hostName = getHostName(addressEpWithLoc).get();
-        return new EndpointHost(endpointHostDataBroker, hostName);
-    }
-
-    public Optional<DataBroker> getPotentialExternalDataBroker(AddressEndpointWithLocation addressEpWithLoc) {
-        ExternalLocationCase externalLocationCase = resolveAndValidateLocation(addressEpWithLoc);
-        InstanceIdentifier<Node> vppNodeIid =
-                (InstanceIdentifier<Node>) externalLocationCase.getExternalNodeMountPoint();
-        String interfacePath = externalLocationCase.getExternalNodeConnector();
-
-        Optional<DataBroker>
-                potentialVppDataProvider = mountedDataBrokerProvider.resolveDataBrokerForMountPoint(vppNodeIid);
-
-        Preconditions.checkArgument(potentialVppDataProvider.isPresent(),
-                "Cannot resolve data broker for interface path: {}", interfacePath);
-
-        return potentialVppDataProvider;
-    }
-
-    public Optional<DataBroker> getPotentialExternalDataBroker(ExternalLocation externalLocation) {
-        InstanceIdentifier<Node> vppNodeIid = (InstanceIdentifier<Node>) externalLocation.getExternalNodeMountPoint();
-
-        Optional<DataBroker> potentialVppDataProvider;
-        potentialVppDataProvider = mountedDataBrokerProvider.resolveDataBrokerForMountPoint(vppNodeIid);
-
-        Preconditions.checkState(potentialVppDataProvider.isPresent(), "Data Broker missing");
-
-        return potentialVppDataProvider;
-    }
-
-    public Optional<DataBroker> getPotentialExternalDataBroker(VppEndpoint vppEp) {
-        InstanceIdentifier<Node> vppNodeIid = VppIidFactory.getNetconfNodeIid(vppEp.getVppNodeId());
-        Optional<DataBroker> potentialVppDataProvider =
-                mountedDataBrokerProvider.resolveDataBrokerForMountPoint(vppNodeIid);
-
-        Preconditions.checkArgument(potentialVppDataProvider.isPresent(),
-                "Cannot resolve data broker for Vpp Endpoint: {}", vppEp);
-        return potentialVppDataProvider;
-    }
-
-    public Optional<DataBroker> getPotentialExternalDataBroker(String hostId) {
-        InstanceIdentifier<Node> nodeIid = VppIidFactory.getNetconfNodeIid(new NodeId(hostId));
-        Optional<DataBroker> potentialVppDataProvider =
-                mountedDataBrokerProvider.resolveDataBrokerForMountPoint(nodeIid);
-        Preconditions.checkArgument(potentialVppDataProvider.isPresent(),
-                "Data Broker not found for {}", hostId);
-        return potentialVppDataProvider;
-    }
-
-    public Optional<String> getHostName(AddressEndpointWithLocation addrEp) {
-        ExternalLocationCase locationCase = resolveAndValidateLocation(addrEp);
-        NodeKey nodeKey = locationCase.getExternalNodeMountPoint().firstKeyOf(Node.class);
-        String hostId = Preconditions.checkNotNull(nodeKey.getNodeId().getValue(),
-                "Host Id extraction failed from address endpoint: {}", addrEp);
-        return Optional.fromNullable(hostId);
-    }
-
-    public Optional<String> getHostName(ExternalLocation externalLocation) {
-        NodeKey nodeKey = externalLocation.getExternalNodeMountPoint().firstKeyOf(Node.class);
-        String hostId = Preconditions.checkNotNull(nodeKey.getNodeId().getValue(),
-                "Host Id extraction failed from address endpoint: {}", externalLocation);
-
-        return Optional.fromNullable(hostId);
-    }
 
     public static ExternalLocationCase resolveAndValidateLocation(AddressEndpointWithLocation addrEpWithLoc) {
         Preconditions.checkNotNull(addrEpWithLoc.getAbsoluteLocation(), "Absolute location for " +
@@ -312,9 +242,9 @@ public class ConfigManagerHelper {
         return ip != null;
     }
 
-    public String getLispCpRlocInterfaceName(@Nonnull EndpointHost endpointHost) {
+    public String getLispCpRlocInterfaceName(@Nonnull String hostName) {
         List<Interface> operationalInterfaceList =
-                InterfaceUtil.getOperationalInterfaces(LispUtil.HOSTNAME_TO_IID.apply(endpointHost.getHostName()));
+                InterfaceUtil.getOperationalInterfaces(LispUtil.HOSTNAME_TO_IID.apply(hostName));
 
         if (operationalInterfaceList == null) {
             return null;
@@ -350,10 +280,9 @@ public class ConfigManagerHelper {
         return LispStateManager.DEFAULT_LOCATOR_SET_NAME_PREFIX + "_itr_rloc";
     }
 
-    public String constructEidMappingName(AddressEndpointWithLocation addressEp) {
-        String interfaceName = getInterfaceName(addressEp).get();
+    public String constructEidMappingName(AddressEndpointWithLocation addressEp, String interfaceName) {
         String ipAddress = getInterfaceIp(addressEp).getValue();
-        return LispStateManager.DEFAULT_MAPPINGRECORD_NAME_PREFIX + interfaceName + "_" + ipAddress;
+        return LispStateManager.DEFAULT_MAPPING_RECORD_NAME_PREFIX + interfaceName + "_" + ipAddress;
     }
 
     public String getSubnet(AddressEndpointWithLocation addressEp) {
@@ -371,7 +300,7 @@ public class ConfigManagerHelper {
         return LispUtil.toEid(LispUtil.toIpv4(ipPrefix), vni, Ipv4Afi.class);
     }
 
-    public String getIpWithPrefixOfEndpoint(AddressEndpointWithLocation addressEp) {
+    private static String getIpWithPrefixOfEndpoint(AddressEndpointWithLocation addressEp) {
         String ipPrefix = null;
         if (addressEp.getAddressType().equals(IpPrefixType.class)) {
             ipPrefix = addressEp.getAddress();
@@ -390,7 +319,7 @@ public class ConfigManagerHelper {
         return Preconditions.checkNotNull(ipPrefix, "No IP address found for Address Endpoint: {}", addressEp);
     }
 
-    public Ipv4Address getInterfaceIp(AddressEndpointWithLocation addressEp) {
+    public static Ipv4Address getInterfaceIp(AddressEndpointWithLocation addressEp) {
         String ipPrefix = getIpWithPrefixOfEndpoint(addressEp);
         return LispUtil.toIpv4(ipPrefix).getIpv4();
     }
@@ -426,6 +355,7 @@ public class ConfigManagerHelper {
         return VppPathMapper.interfacePathToInterfaceName(interfacePath);
     }
 
+
     public HmacKey getDefaultHmacKey() {
         return LispUtil.toHmacKey(HmacKeyType.Sha196Key, LispStateManager.DEFAULT_XTR_KEY);
     }
@@ -452,8 +382,8 @@ public class ConfigManagerHelper {
         return addedEp.getRelativeLocations() != null && addedEp.getRelativeLocations().getExternalLocation() != null;
     }
 
-    public boolean isMetadataPort(AddressEndpointWithLocation addressEp) {
-        return hasRelativeLocations(addressEp) || IpAddressUtil.isMetadataIp(getInterfaceIp(addressEp));
+    public static boolean isMetadataPort(AddressEndpointWithLocation addressEp) {
+        return IpAddressUtil.isMetadataIp(getInterfaceIp(addressEp));
     }
 
     public String getGatewayInterfaceName(String gwNamePrefix, String subnetUuid) {