- Adding tunnel-type-mpls-over-gre for distinguishing internal vs external tunnels 75/30375/1
authorFaseela K <faseela.k@ericsson.com>
Mon, 30 Nov 2015 11:15:30 +0000 (16:45 +0530)
committerFaseela K <faseela.k@ericsson.com>
Mon, 30 Nov 2015 11:15:30 +0000 (16:45 +0530)
- Fixing NPE during pre-provisioning of ovs tunnel ports
- Adding two new RPCs in interface manager needed by vpnservice

Change-Id: Ied0cf95c7bf5aa1963cb5c5778e4af8edf27753c
Signed-off-by: Faseela K <faseela.k@ericsson.com>
interfacemgr/interfacemgr-api/src/main/yang/odl-interface-rpc.yang
interfacemgr/interfacemgr-api/src/main/yang/odl-interface.yang
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigAddHelper.java
interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/rpcservice/InterfaceManagerRpcService.java

index 0e4efca05eeca046b9e43ad7ea1d8ed462abc2c5..88ce5ac664d0590aea4bac7c43a959ee6dd99c13 100644 (file)
@@ -10,6 +10,14 @@ module odl-interface-rpc {
         prefix odlif; revision-date 2015-03-31;
     }
 
+    import opendaylight-inventory {
+        prefix inv; revision-date 2013-08-19;
+    }
+
+    import ietf-interfaces {
+        prefix if; revision-date 2014-05-08;
+    }
+
     import opendaylight-action-types {prefix action;}
     import opendaylight-flow-types {prefix offlow;revision-date "2013-10-26";}
 
@@ -53,33 +61,6 @@ module odl-interface-rpc {
         }
     }
 
-    rpc get-interface-from-port {
-        description "used to retrieve interface from port details";
-        input {
-            leaf interface-type {
-                description "Type of the interface (vlan/gre or vxlan tunnel)";
-                type identityref {
-                    base odlif:tunnel-type-base;
-                }
-            }
-            leaf dpid {
-                type uint64;
-            }
-            leaf portno {
-                type uint32;
-            }
-            leaf interface-id {
-                description "Used to provide the interface specific differentiator information (vlanId/gre-key/vxlan-vni)";
-                type uint64;
-            }
-        }
-        output {
-            leaf interface-name {
-                type string;
-            }
-        }
-    }
-
     rpc get-egress-actions-for-interface {
         description "used to retrieve group actions to use from interface name";
         input {
@@ -117,4 +98,34 @@ module odl-interface-rpc {
             }
         }
     }
+
+    rpc get-interface-type {
+    description "to get the type of the interface(vlan/vxlan or gre)";
+        input {
+            leaf intf-name {
+                type string;
+            }
+        }
+        output {
+            leaf interface-type {
+                type identityref {
+                    base if:interface-type;
+                }
+            }
+        }
+    }
+
+    rpc get-nodeconnector-id-from-interface {
+    description "to get nodeconnector id associated with an interface";
+        input {
+            leaf intf-name {
+                type string;
+            }
+        }
+        output {
+            leaf nodeconnector-id {
+                type inv:node-connector-id;
+            }
+        }
+    }
 }
\ No newline at end of file
index 38405be01414d4a3b8b05e61692105f32f2f438a..9f6308e3acd26b86ef5caffc09480d884d73aa7c 100644 (file)
@@ -70,6 +70,11 @@ module odl-interface {
         base tunnel-type-base;
     }
 
+    identity tunnel-type-mpls-over-gre {
+        description "Tunnel type for mpls over gre tunnels";
+        base tunnel-type-base;
+    }
+
     /* base/common properties */
     augment "/if:interfaces/if:interface" {
         status deprecated;
index 49f5da22feb641edae9ad61fbc6d0acdc4b2c6bf..8a03e5e11db66e524ca03c694a875767ace77f79 100644 (file)
@@ -139,11 +139,6 @@ public class OvsInterfaceConfigAddHelper {
 
         createBridgeEntryIfNotPresent(dpId, dataBroker, t);
 
-        BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
-        InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
-                InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
-        BridgeRefEntry bridgeRefEntry =
-                InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
         BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpId);
         BridgeInterfaceEntryKey bridgeInterfaceEntryKey = new BridgeInterfaceEntryKey(interfaceNew.getName());
 
@@ -152,15 +147,24 @@ public class OvsInterfaceConfigAddHelper {
                     interfaceNew.getName(), t);
         futures.add(t.submit());
 
-        InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
-                (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
-        Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
-                IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
-        if (bridgeNodeOptional.isPresent()) {
-            OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
-            String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
-            SouthboundUtils.addPortToBridge(bridgeIid, interfaceNew,
-                    ovsdbBridgeAugmentation, bridgeName, interfaceNew.getName(), dataBroker, futures);
+        // create bridge on switch, if switch is connected
+        BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
+        InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
+                InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
+        BridgeRefEntry bridgeRefEntry =
+                InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
+        if(bridgeRefEntry != null && bridgeRefEntry.getBridgeReference() != null) {
+            LOG.debug("creating bridge interface on dpn {}", bridgeEntryKey);
+            InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
+                    (InstanceIdentifier<OvsdbBridgeAugmentation>) bridgeRefEntry.getBridgeReference().getValue();
+            Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
+                    IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
+            if (bridgeNodeOptional.isPresent()) {
+                OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
+                String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
+                SouthboundUtils.addPortToBridge(bridgeIid, interfaceNew,
+                        ovsdbBridgeAugmentation, bridgeName, interfaceNew.getName(), dataBroker, futures);
+            }
         }
     }
 
index fbf86df8b5f0201a35de1505f7a2a28962fde38f..a2d26912b2ef4268f6f2415216f22c8587466593 100644 (file)
@@ -135,6 +135,24 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
         return Futures.immediateFuture(rpcResultBuilder.build());
     }
 
+    @Override
+    public Future<RpcResult<GetInterfaceTypeOutput>> getInterfaceType(GetInterfaceTypeInput input) {
+        String interfaceName = input.getIntfName();
+        RpcResultBuilder<GetInterfaceTypeOutput> rpcResultBuilder;
+        try {
+            InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
+            Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
+
+            GetInterfaceTypeOutputBuilder output = new GetInterfaceTypeOutputBuilder().setInterfaceType(interfaceInfo.getType());
+            rpcResultBuilder = RpcResultBuilder.success();
+            rpcResultBuilder.withResult(output.build());
+        } catch (Exception e) {
+            LOG.error("Retrieval of interface type for the key {} failed due to {}", interfaceName, e);
+            rpcResultBuilder = RpcResultBuilder.failed();
+        }
+        return Futures.immediateFuture(rpcResultBuilder.build());
+    }
+
     @Override
     public Future<RpcResult<GetEgressActionsForInterfaceOutput>> getEgressActionsForInterface(GetEgressActionsForInterfaceInput input) {
         RpcResultBuilder<GetEgressActionsForInterfaceOutput> rpcResultBuilder;
@@ -151,25 +169,6 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
         return Futures.immediateFuture(rpcResultBuilder.build());
     }
 
-    public static InstanceIdentifier<InterfaceChildEntry> getInterfaceChildEntryIdentifier(InterfaceParentEntryKey parentEntryKey, InterfaceChildEntryKey interfaceChildEntryKey) {
-        InstanceIdentifier.InstanceIdentifierBuilder<InterfaceChildEntry> interfaceChildEntryInstanceIdentifierBuilder =
-                InstanceIdentifier.builder(InterfaceChildInfo.class).child(InterfaceParentEntry.class, parentEntryKey).child(InterfaceChildEntry.class, interfaceChildEntryKey);
-        return interfaceChildEntryInstanceIdentifierBuilder.build();
-    }
-
-    public static InterfaceChildEntry getInterfaceChildEntryFromConfigDS(String interfaceName,
-                                                         DataBroker dataBroker) {
-        InterfaceParentEntryKey parentEntryKey = new InterfaceParentEntryKey(interfaceName);
-        InterfaceChildEntryKey childEntryKey = new InterfaceChildEntryKey(interfaceName);
-        InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryInstanceIdentifier = getInterfaceChildEntryIdentifier(parentEntryKey, childEntryKey);
-        Optional<InterfaceChildEntry> interfaceChildEntryOptional =
-                IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfaceChildEntryInstanceIdentifier, dataBroker);
-        if (!interfaceChildEntryOptional.isPresent()) {
-            return null;
-        }
-        return interfaceChildEntryOptional.get();
-    }
-
     @Override
     public Future<RpcResult<GetPortFromInterfaceOutput>> getPortFromInterface(GetPortFromInterfaceInput input) {
         RpcResultBuilder<GetPortFromInterfaceOutput> rpcResultBuilder;
@@ -196,28 +195,23 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
     }
 
     @Override
-    public Future<RpcResult<GetInterfaceFromPortOutput>> getInterfaceFromPort(GetInterfaceFromPortInput input) {
-        /*RpcResultBuilder<GetInterfaceFromPortOutput> rpcResultBuilder;
+    public Future<RpcResult<GetNodeconnectorIdFromInterfaceOutput>> getNodeconnectorIdFromInterface(GetNodeconnectorIdFromInterfaceInput input) {
+        String interfaceName = input.getIntfName();
+        RpcResultBuilder<GetNodeconnectorIdFromInterfaceOutput> rpcResultBuilder;
         try {
-            Interface interfaceInfo = null;
-            NodeId nodeId = IfmUtil.buildDpnNodeId(input.getDpid());
-            Node node = getNodeFromInventoryOperDS(nodeId, dataBroker);
-            ChildInterfaceNames childInterfaceNames = node.getAugmentation(ChildInterfaceNames.class);
-            for(OfInterfaceRefInfo ofInterfaceRefInfo : childInterfaceNames.getOfInterfaceRefInfo()){
-               interfaceInfo = getInterfaceFromTunnelKey(ofInterfaceRefInfo.getOfIntfName(), input.getInterfaceId(),
-                       input.getInterfaceType());
-            }
-            GetInterfaceFromPortOutputBuilder output = new GetInterfaceFromPortOutputBuilder().
-                    setInterfaceName(interfaceInfo == null ? null : interfaceInfo.getName());
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
+                    InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker);
+            String lowerLayerIf = ifState.getLowerLayerIf().get(0);
+            NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
+
+            GetNodeconnectorIdFromInterfaceOutputBuilder output = new GetNodeconnectorIdFromInterfaceOutputBuilder().setNodeconnectorId(nodeConnectorId);
             rpcResultBuilder = RpcResultBuilder.success();
             rpcResultBuilder.withResult(output.build());
-        }catch(Exception e){
-            LOG.error("Retrieval of interface for the key {} failed due to {}" ,input.getPortno(), e);
+        } catch (Exception e) {
+            LOG.error("Retrieval of nodeconnector id for the key {} failed due to {}", interfaceName, e);
             rpcResultBuilder = RpcResultBuilder.failed();
         }
         return Futures.immediateFuture(rpcResultBuilder.build());
-        */
-        return null;
     }
 
     public List<ActionInfo> getEgressActionInfosForInterface(String interfaceName) {
@@ -271,46 +265,4 @@ public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
         return null;
     }
 
-    public static Node getNodeFromInventoryOperDS(NodeId nodeId, DataBroker dataBroker) {
-        InstanceIdentifier<Node> nodeIdentifier = InstanceIdentifier.builder(Nodes.class)
-                .child(Node.class, new NodeKey(nodeId)).build();
-
-        Optional<Node> nodeOptional = IfmUtil.read(LogicalDatastoreType.OPERATIONAL,
-                nodeIdentifier, dataBroker);
-        if (!nodeOptional.isPresent()) {
-            return null;
-        }
-        return nodeOptional.get();
-    }
-
-    public Interface getInterfaceFromTunnelKey(String interfaceName, BigInteger tunnelKey,
-                                               Class<? extends TunnelTypeBase> ifType){
-
-        /*Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName), dataBroker);
-
-        if(ifType.isAssignableFrom(IfL2vlan.class)){
-            IfL2vlan vlanIface = interfaceInfo.getAugmentation(IfL2vlan.class);
-            LOG.trace("L2Vlan: {}",vlanIface);
-            long vlanVid = (vlanIface == null) ? 0 : vlanIface.getVlanId();
-            if(tunnelKey.intValue() == vlanVid){
-               return interfaceInfo;
-            }
-        }else if(ifType.isAssignableFrom(TunnelTypeBase.class)){
-            IfTunnel ifTunnel = interfaceInfo.getAugmentation(IfTunnel.class);
-            TunnelResources tunnelResources = ifTunnel.getTunnelResources();
-            if(ifType.isAssignableFrom(TunnelTypeGre.class)) {
-                IfGre ifGre = tunnelResources.getAugmentation(IfGre.class);
-                if (ifGre.getGreKey() == tunnelKey) {
-                    return interfaceInfo;
-                }
-            }else if(ifType.isAssignableFrom(TunnelTypeVxlan.class)){
-                IfVxlan ifVxlan = tunnelResources.getAugmentation(IfVxlan.class);
-                if(ifVxlan.getVni() == tunnelKey){
-                    return interfaceInfo;
-                }
-            }
-        }
-        return null;*/
-        return null;
-    }
 }
\ No newline at end of file