From: Vivek Srivastava Date: Tue, 5 Jan 2016 08:20:49 +0000 (+0000) Subject: Merge "Vpnmanager and fibmanager changes 1. Merge fib and nexthop manager 2. Integrat... X-Git-Tag: release/beryllium~70 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=5d2782271254a36a90b8a71a7f65db688ac0b1ef;hp=fd902f24e59b49b7c0461cb2862e77c2134bec6f;p=vpnservice.git Merge "Vpnmanager and fibmanager changes 1. Merge fib and nexthop manager 2. Integrate with interface manager, itm and arpmanager" --- diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmUtil.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmUtil.java index 26366286..44f754e8 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmUtil.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/IfmUtil.java @@ -26,6 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.AllocateIdInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.AllocateIdInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.AllocateIdOutput; @@ -191,4 +192,12 @@ public class IfmUtil { LOG.warn("Exception when releasing Id for key {}", idKey, e); } } + + public static BigInteger getDpnId(DatapathId datapathId){ + if (datapathId != null) { + String dpIdStr = datapathId.getValue().replace(":", ""); + return new BigInteger(dpIdStr, 16); + } + return null; + } } diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateRemoveHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateRemoveHelper.java index fb3ac13a..2aa85d26 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateRemoveHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateRemoveHelper.java @@ -51,7 +51,9 @@ public class OvsInterfaceStateRemoveHelper { /* Remove entry from if-index-interface-name map and deallocate Id from Idmanager. */ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(portName, dataBroker); - InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, interfaceState.getName(), interfaceState.getIfIndex()); + if(interfaceState != null) { + InterfaceMetaUtils.removeLportTagInterfaceMap(transaction, idManager, dataBroker, interfaceState.getName(), interfaceState.getIfIndex()); + } transaction.delete(LogicalDatastoreType.OPERATIONAL, ifStateId); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateAddHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateAddHelper.java index 4b426a09..4fa4c1bf 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateAddHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateAddHelper.java @@ -28,8 +28,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.met import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel; -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.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,29 +54,23 @@ public class OvsInterfaceTopologyStateAddHelper { return futures; } } - - String dpId = bridgeNew.getDatapathId().getValue(); String bridgeName = bridgeNew.getBridgeName().getValue(); - LOG.info("adding dpId {} to bridge reference {}", dpId, bridgeNew); + BigInteger dpnId = IfmUtil.getDpnId(bridgeNew.getDatapathId()); - if (dpId == null) { - LOG.error("Optained null dpid for bridge: {}", bridgeNew); + if (dpnId == null) { + LOG.warn("Got Null DPID for Bridge: {}", bridgeNew); return futures; } - String datapathId = dpId.replaceAll("[^\\d.]", ""); - BigInteger ovsdbDpId = new BigInteger(datapathId, 16); - - LOG.info("adding dpId {} to bridge reference {}", datapathId, bridgeName); - BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(ovsdbDpId); + BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId); InstanceIdentifier bridgeEntryId = InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey); BridgeRefEntryBuilder tunnelDpnBridgeEntryBuilder = - new BridgeRefEntryBuilder().setKey(bridgeRefEntryKey).setDpid(ovsdbDpId) + new BridgeRefEntryBuilder().setKey(bridgeRefEntryKey).setDpid(dpnId) .setBridgeReference(new OvsdbBridgeRef(bridgeIid)); t.put(LogicalDatastoreType.OPERATIONAL, bridgeEntryId, tunnelDpnBridgeEntryBuilder.build(), true); - BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(ovsdbDpId); + BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpnId); InstanceIdentifier bridgeEntryInstanceIdentifier = InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey); BridgeEntry bridgeEntry = diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateRemoveHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateRemoveHelper.java index b38708a0..90fcf360 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateRemoveHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceTopologyStateRemoveHelper.java @@ -11,6 +11,7 @@ import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.vpnservice.interfacemgr.IfmUtil; import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntry; @@ -30,16 +31,13 @@ public class OvsInterfaceTopologyStateRemoveHelper { OvsdbBridgeAugmentation bridgeOld, DataBroker dataBroker) { List> futures = new ArrayList<>(); WriteTransaction t = dataBroker.newWriteOnlyTransaction();; + BigInteger dpnId = IfmUtil.getDpnId(bridgeOld.getDatapathId()); - String dpId = bridgeOld.getDatapathId().getValue().replaceAll("[^\\d.]", ""); - if (dpId == null) { + if (dpnId == null) { LOG.warn("Got Null DPID for Bridge: {}", bridgeOld); return futures; } - - dpId = dpId.replaceAll("[^\\d.]", ""); - BigInteger ovsdbDpId = new BigInteger(dpId,16); - BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(ovsdbDpId); + BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpnId); InstanceIdentifier bridgeEntryId = InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey); t.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java index de503d11..e34e2b06 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java @@ -40,7 +40,7 @@ public class FlowBasedServicesConfigBindHelper { public static List> bindService(InstanceIdentifier instanceIdentifier, BoundServices boundServiceNew, DataBroker dataBroker) { List> futures = new ArrayList<>(); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); String interfaceName = InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getInterfaceName(); @@ -77,22 +77,18 @@ public class FlowBasedServicesConfigBindHelper { int vlanId = 0; List matches = null; if (iface.getType().isAssignableFrom(L2vlan.class)) { - IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); - if( l2vlan != null){ - vlanId = l2vlan.getVlanId().getValue(); - } - matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, vlanId); + matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface); } else if (iface.getType().isAssignableFrom(Tunnel.class)){ matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface); } if (matches != null) { - FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface.getName(), vlanId, boundServiceNew, - dataBroker, t, matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE); + FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew, + transaction, matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE); } - if (t != null) { - futures.add(t.submit()); + if (transaction != null) { + futures.add(transaction.submit()); } return futures; } @@ -111,35 +107,37 @@ public class FlowBasedServicesConfigBindHelper { highestPriority = boundService.getServicePriority(); } } - LOG.error("Reached unexpected part 1 of the code when handling bind service for interface: {}, when binding" + - "service: {}", iface, boundServiceNew); } if (!isCurrentServiceHighestPriority) { - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundServiceNew, iface, dataBroker, t, + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundServiceNew, iface, transaction, ifState.getIfIndex()); } else { BoundServices serviceToReplace = tmpServicesMap.get(highestPriority); - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, serviceToReplace, iface, dataBroker, t, + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, serviceToReplace, iface, transaction, ifState.getIfIndex()); - int vlanId = 0; List matches = null; if (iface.getType().isAssignableFrom(L2vlan.class)) { - vlanId = iface.getAugmentation(IfL2vlan.class).getVlanId().getValue(); - matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, vlanId); + matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface); } else if (iface.getType().isAssignableFrom(Tunnel.class)){ matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface); } if (matches != null) { - FlowBasedServicesUtils.removeIngressFlow(iface, serviceToReplace, dpId, dataBroker, t); - FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface.getName(), vlanId, boundServiceNew, dataBroker, t, + + WriteTransaction removeFlowTransaction = dataBroker.newWriteOnlyTransaction(); + FlowBasedServicesUtils.removeIngressFlow(iface, serviceToReplace, dpId, removeFlowTransaction); + futures.add(removeFlowTransaction.submit()); + + WriteTransaction installFlowTransaction = dataBroker.newWriteOnlyTransaction(); + FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, boundServiceNew, installFlowTransaction, matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE); + futures.add(installFlowTransaction.submit()); } } - if (t != null) { - futures.add(t.submit()); + if (transaction != null) { + futures.add(transaction.submit()); } return futures; } diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java index bfeed508..e18072c7 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java @@ -65,17 +65,10 @@ public class FlowBasedServicesConfigUnbindHelper { long portNo = Long.parseLong(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId)); BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); - int vlanId = 0; - if (iface.getType().isAssignableFrom(L2vlan.class)) { - IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); - if(l2vlan != null) { - vlanId = iface.getAugmentation(IfL2vlan.class).getVlanId().getValue(); - } - } List boundServices = servicesInfo.getBoundServices(); if (boundServices.isEmpty()) { // Remove entry from Ingress Table. - FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, dataBroker, t); + FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, t); if (t != null) { futures.add(t.submit()); } @@ -92,7 +85,7 @@ public class FlowBasedServicesConfigUnbindHelper { } if (highestPriority < boundServiceOld.getServicePriority()) { - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, dataBroker, t); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t); if (t != null) { futures.add(t.submit()); } @@ -101,16 +94,16 @@ public class FlowBasedServicesConfigUnbindHelper { List matches = null; if (iface.getType().isAssignableFrom(L2vlan.class)) { - matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, vlanId); + matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface); } else if (iface.getType().isAssignableFrom(Tunnel.class)){ matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface); } BoundServices toBeMoved = tmpServicesMap.get(highestPriority); - FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, dataBroker, t); - FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface.getName(), vlanId, toBeMoved, dataBroker, t, + FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, t); + FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, toBeMoved, t, matches, ifState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE); - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, toBeMoved, dataBroker, t); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, toBeMoved, t); if (t != null) { futures.add(t.submit()); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java index 916fc11a..b1c4d489 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java @@ -64,28 +64,21 @@ public class FlowBasedServicesStateBindHelper { NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker); long portNo = Long.parseLong(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId)); BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); - Long lportTag = FlowBasedServicesUtils.getLPortTag(iface, dataBroker); - int vlanId = 0; List matches = null; if (iface.getType().isAssignableFrom(L2vlan.class)) { - IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); - if(l2vlan != null) { - vlanId = l2vlan.getVlanId().getValue(); - } - matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, vlanId); + matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface); } else if (iface.getType().isAssignableFrom(Tunnel.class)){ matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface); } if (matches != null) { - FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface.getName(), vlanId, highestPriorityBoundService, - dataBroker, t, matches, lportTag.intValue(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE); + FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, highestPriorityBoundService, + t, matches, ifaceState.getIfIndex(), IfmConstants.VLAN_INTERFACE_INGRESS_TABLE); } for (BoundServices boundService : allServices) { if (!boundService.equals(highestPriorityBoundService)) { - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, iface, - dataBroker, t, lportTag.intValue()); + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, iface, t, ifaceState.getIfIndex()); } } diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java index 362a3bdf..aa0b9bc2 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java @@ -61,12 +61,11 @@ public class FlowBasedServicesStateUnbindHelper { return futures; } BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); - FlowBasedServicesUtils.removeIngressFlow(iface, highestPriorityBoundService, dpId, - dataBroker, t); + FlowBasedServicesUtils.removeIngressFlow(iface, highestPriorityBoundService, dpId, t); for (BoundServices boundService : allServices) { if (!boundService.equals(highestPriorityBoundService)) { - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundService, dataBroker, t); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundService, t); } } diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java index 221bff99..bcaff79d 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java @@ -35,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.serviceb import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfoKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.services.info.BoundServices; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,9 +71,14 @@ public class FlowBasedServicesUtils { return null; } - public static List getMatchInfoForVlanPortAtIngressTable(BigInteger dpId, long portNo, long vlanId) { + public static List getMatchInfoForVlanPortAtIngressTable(BigInteger dpId, long portNo, Interface iface) { List matches = new ArrayList<>(); matches.add(new MatchInfo(MatchFieldType.in_port, new BigInteger[] {dpId, BigInteger.valueOf(portNo)})); + int vlanId = 0; + IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); + if(l2vlan != null){ + vlanId = l2vlan.getVlanId().getValue(); + } if (vlanId > 0) { LOG.error("VlanId matching support is not fully available in Be."); matches.add(new MatchInfo(MatchFieldType.vlan_vid, new long[]{vlanId})); @@ -116,14 +122,19 @@ public class FlowBasedServicesUtils { return 0L; } - public static void installInterfaceIngressFlow(BigInteger dpId, String interfaceName, int vlanId, + public static void installInterfaceIngressFlow(BigInteger dpId, Interface iface, BoundServices boundServiceNew, - DataBroker dataBroker, WriteTransaction t, + WriteTransaction t, List matches, int lportTag, short tableId) { List instructions = boundServiceNew.getAugmentation(StypeOpenflow.class).getInstruction(); int serviceInstructionsSize = instructions.size(); List instructionSet = new ArrayList(); + int vlanId = 0; + IfL2vlan l2vlan = iface.getAugmentation(IfL2vlan.class); + if(l2vlan != null){ + vlanId = l2vlan.getVlanId().getValue(); + } if (vlanId != 0) { // incrementing instructionSize and using it as actionKey. Because it won't clash with any other instructions int actionKey = ++serviceInstructionsSize; @@ -153,7 +164,7 @@ public class FlowBasedServicesUtils { } String serviceRef = boundServiceNew.getServiceName(); - String flowRef = getFlowRef(dpId, interfaceName, boundServiceNew); + String flowRef = getFlowRef(dpId, iface.getName(), boundServiceNew); StypeOpenflow stypeOpenflow = boundServiceNew.getAugmentation(StypeOpenflow.class); Flow ingressFlow = MDSALUtil.buildFlowNew(tableId, flowRef, stypeOpenflow.getFlowPriority(), serviceRef, 0, 0, @@ -190,7 +201,7 @@ public class FlowBasedServicesUtils { } public static void installLPortDispatcherFlow(BigInteger dpId, BoundServices boundService, Interface iface, - DataBroker dataBroker, WriteTransaction t, int interfaceTag) { + WriteTransaction t, int interfaceTag) { LOG.debug("Installing LPort Dispatcher Flows {}, {}", dpId, iface); short serviceIndex = boundService.getServicePriority(); String serviceRef = boundService.getServiceName(); @@ -226,8 +237,7 @@ public class FlowBasedServicesUtils { installFlow(dpId, ingressFlow, t); } - public static void removeIngressFlow(Interface iface, BoundServices serviceOld, BigInteger dpId, - DataBroker dataBroker, WriteTransaction t) { + public static void removeIngressFlow(Interface iface, BoundServices serviceOld, BigInteger dpId, WriteTransaction t) { LOG.debug("Removing Ingress Flows"); String flowKeyStr = getFlowRef(dpId, iface.getName(), serviceOld); FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr)); @@ -239,15 +249,13 @@ public class FlowBasedServicesUtils { t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); } - public static void removeLPortDispatcherFlow(BigInteger dpId, Interface iface, BoundServices boundServicesOld, - DataBroker dataBroker, WriteTransaction t) { + public static void removeLPortDispatcherFlow(BigInteger dpId, Interface iface, BoundServices boundServicesOld, WriteTransaction t) { LOG.debug("Removing LPort Dispatcher Flows {}, {}", dpId, iface); - Long interfaceTag = FlowBasedServicesUtils.getLPortTag(iface, dataBroker); StypeOpenflow stypeOpenFlow = boundServicesOld.getAugmentation(StypeOpenflow.class); - String flowKeyStr = iface.getName() + boundServicesOld.getServicePriority() + - boundServicesOld.getServiceName() + stypeOpenFlow.getDispatcherTableId(); - FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr)); + // build the flow and install it + String flowRef = getFlowRef(dpId, iface.getName(), boundServicesOld); + FlowKey flowKey = new FlowKey(new FlowId(flowRef)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) diff --git a/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/StateInterfaceTest.java b/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/StateInterfaceTest.java index 6bff195a..489031c4 100644 --- a/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/StateInterfaceTest.java +++ b/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/StateInterfaceTest.java @@ -24,21 +24,29 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.vpnservice.interfacemgr.IfmConstants; import org.opendaylight.vpnservice.interfacemgr.IfmUtil; import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils; +import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils; import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceStateAddHelper; import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceStateRemoveHelper; +import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.OvsInterfaceStateUpdateHelper; import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.*; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.IfIndexesInterfaceMap; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeGre; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -61,12 +69,15 @@ public class StateInterfaceTest { FlowCapableNodeConnector fcNodeConnectorNew = null; Interface vlanInterfaceEnabled = null; Interface vlanInterfaceDisabled = null; + InterfaceParentEntryKey interfaceParentEntryKey = null; IfIndexInterface IfindexInterface = null; InstanceIdentifier interfaceInstanceIdentifier = null; InstanceIdentifier fcNodeConnectorId = null; InstanceIdentifier ifIndexId =null; InstanceIdentifier interfaceStateIdentifier = null; + InstanceIdentifier interfaceParentEntryIdentifier = null; org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface stateInterface; + InterfaceParentEntry interfaceParentEntry; @Mock DataBroker dataBroker; @Mock IdManagerService idManager; @@ -77,6 +88,7 @@ public class StateInterfaceTest { OvsInterfaceStateAddHelper addHelper; OvsInterfaceStateRemoveHelper removeHelper; + OvsInterfaceStateUpdateHelper updateHelper; @Before public void setUp() throws Exception { @@ -94,12 +106,14 @@ public class StateInterfaceTest { nodeConnector = InterfaceManagerTestUtil.buildFlowCapableNodeConnector(nodeConnectorId); fcNodeConnectorNew = nodeConnector.getAugmentation(FlowCapableNodeConnector.class); fcNodeConnectorId = InterfaceManagerTestUtil.getFlowCapableNodeConnectorIdentifier("openflow:1", nodeConnectorId); - IfindexInterface = InterfaceManagerTestUtil.buildIfIndexInterface(100,InterfaceManagerTestUtil.interfaceName); + IfindexInterface = InterfaceManagerTestUtil.buildIfIndexInterface(100, InterfaceManagerTestUtil.interfaceName); ifIndexId = InstanceIdentifier.builder(IfIndexesInterfaceMap.class).child(IfIndexInterface.class, new IfIndexInterfaceKey(100)).build(); interfaceInstanceIdentifier = InterfaceManagerCommonUtils.getInterfaceIdentifier(new InterfaceKey(InterfaceManagerTestUtil.interfaceName)); interfaceStateIdentifier = IfmUtil.buildStateInterfaceId(InterfaceManagerTestUtil.interfaceName); vlanInterfaceEnabled = InterfaceManagerTestUtil.buildInterface(InterfaceManagerTestUtil.interfaceName, "Test Vlan Interface1", true, L2vlan.class, BigInteger.valueOf(1)); vlanInterfaceDisabled = InterfaceManagerTestUtil.buildInterface(InterfaceManagerTestUtil.interfaceName, "Test Vlan Interface1", false, L2vlan.class, BigInteger.valueOf(1)); + interfaceParentEntryKey = new InterfaceParentEntryKey(InterfaceManagerTestUtil.interfaceName); + interfaceParentEntryIdentifier = InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey); org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder ifaceBuilder = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder(); List lowerLayerIfList = new ArrayList<>(); lowerLayerIfList.add(nodeConnectorId.getValue()); @@ -108,7 +122,13 @@ public class StateInterfaceTest { .setIfIndex(100) .setLowerLayerIf(lowerLayerIfList); ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(InterfaceManagerTestUtil.interfaceName)); + stateInterface = ifaceBuilder.build(); + + InterfaceParentEntryBuilder ifaceParentEntryBuilder = new InterfaceParentEntryBuilder(); + List ifaceChildEntryList= new ArrayList<>(); + interfaceParentEntry = ifaceParentEntryBuilder.setInterfaceChildEntry(ifaceChildEntryList).build(); + when(dataBroker.newReadOnlyTransaction()).thenReturn(mockReadTx); when(dataBroker.newWriteOnlyTransaction()).thenReturn(mockWriteTx); } @@ -157,4 +177,36 @@ public class StateInterfaceTest { verify(mockWriteTx).delete(LogicalDatastoreType.OPERATIONAL, ifIndexId); } + @Test + public void testUpdateStateInterface(){ + + Optional + expectedStateInterface = Optional.of(stateInterface); + OptionalexpectedParentEntry = Optional.of(interfaceParentEntry); + + doReturn(Futures.immediateCheckedFuture(expectedStateInterface)).when(mockReadTx).read( + LogicalDatastoreType.OPERATIONAL, interfaceStateIdentifier); + doReturn(Futures.immediateCheckedFuture(expectedParentEntry)).when(mockReadTx).read( + LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier); + + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder ifaceBuilder = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder(); + ifaceBuilder.setAdminStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus.Up) + .setPhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress.getDefaultInstance("AA:AA:AA:AA:AA:AA")); + ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(InterfaceManagerTestUtil.interfaceName)); + + stateInterface = ifaceBuilder.build(); + + FlowCapableNodeConnectorBuilder fcNodeConnectorOldupdate = new FlowCapableNodeConnectorBuilder().setHardwareAddress(MacAddress.getDefaultInstance("AA:AA:AA:AA:AA:AB")); + FlowCapableNodeConnectorBuilder fcNodeConnectorNewupdate = new FlowCapableNodeConnectorBuilder().setHardwareAddress(MacAddress.getDefaultInstance("AA:AA:AA:AA:AA:AA")); + + StateBuilder b2 = new StateBuilder().setBlocked(true).setLinkDown(true); + StateBuilder b3 = new StateBuilder().setBlocked(false).setLinkDown(true); + + fcNodeConnectorOldupdate.setState(b2.build()); + fcNodeConnectorNewupdate.setState(b3.build()); + + updateHelper.updateState(fcNodeConnectorId, dataBroker, InterfaceManagerTestUtil.interfaceName, fcNodeConnectorNewupdate.build(), fcNodeConnectorOldupdate.build()); + + verify(mockWriteTx).merge(LogicalDatastoreType.OPERATIONAL,interfaceStateIdentifier,stateInterface); + } } \ No newline at end of file diff --git a/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/TopologyStateInterfaceTest.java b/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/TopologyStateInterfaceTest.java new file mode 100644 index 00000000..914e8cf1 --- /dev/null +++ b/interfacemgr/interfacemgr-impl/src/test/java/org/opendaylight/vpnservice/interfacemgr/test/TopologyStateInterfaceTest.java @@ -0,0 +1,169 @@ +/** + * Created by eranjsu on 28-Dec-15. + */ +package org.opendaylight.vpnservice.interfacemgr.test; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.Futures; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +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.LogicalDatastoreType; +import org.opendaylight.vpnservice.interfacemgr.IfmConstants; +import org.opendaylight.vpnservice.interfacemgr.IfmUtil; +import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils; +import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils; +import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers.*; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.*; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.IfIndexesInterfaceMap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._if.indexes._interface.map.IfIndexInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.BridgeEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.BridgeEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.bridge.entry.BridgeInterfaceEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.bridge.entry.BridgeInterfaceEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge._interface.info.bridge.entry.BridgeInterfaceEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007.bridge.ref.info.BridgeRefEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.TunnelTypeGre; +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.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; + +import javax.swing.plaf.nimbus.State; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; + +import static org.mockito.Mockito.*; + + +@RunWith(MockitoJUnitRunner.class) +public class TopologyStateInterfaceTest { + + BigInteger dpId = BigInteger.valueOf(1); + InstanceIdentifierbridgeIid = null; + InstanceIdentifier bridgeEntryIid = null; + OvsdbBridgeAugmentation bridgeNew; + OvsdbBridgeAugmentation bridgeOld; + BridgeEntry bridgeEntry = null; + ParentRefs parentRefs = null; + InstanceIdentifier interfaceInstanceIdentifier = null; + Interface tunnelInterfaceEnabled = null; + BridgeInterfaceEntry bridgeInterfaceEntry; + BridgeInterfaceEntryKey bridgeInterfaceEntryKey; + + @Mock DataBroker dataBroker; + @Mock ListenerRegistration dataChangeListenerRegistration; + @Mock ReadOnlyTransaction mockReadTx; + @Mock WriteTransaction mockWriteTx; + + OvsInterfaceTopologyStateAddHelper addHelper; + OvsInterfaceTopologyStateRemoveHelper removeHelper; + + @Before + public void setUp() throws Exception { + when(dataBroker.registerDataChangeListener( + any(LogicalDatastoreType.class), + any(InstanceIdentifier.class), + any(DataChangeListener.class), + any(DataChangeScope.class))) + .thenReturn(dataChangeListenerRegistration); + setupMocks(); + } + + private void setupMocks() + { + Node node = new NodeBuilder().setKey(null).setNodeId(null).build(); + tunnelInterfaceEnabled = InterfaceManagerTestUtil.buildTunnelInterface(dpId, InterfaceManagerTestUtil.tunnelInterfaceName, "Test Interface1", true, TunnelTypeGre.class + , "192.168.56.101", "192.168.56.102"); + bridgeIid = InterfaceManagerTestUtil.getOvsdbAugmentationInstanceIdentifier(InterfaceManagerTestUtil.interfaceName, node); + bridgeNew = InterfaceManagerTestUtil.getOvsdbBridgeRef("s1"); + bridgeOld = InterfaceManagerTestUtil.getOvsdbBridgeRef("s1"); + bridgeEntryIid = InterfaceMetaUtils.getBridgeEntryIdentifier(new BridgeEntryKey(dpId)); + interfaceInstanceIdentifier = IfmUtil.buildId(InterfaceManagerTestUtil.tunnelInterfaceName); + bridgeInterfaceEntryKey = new BridgeInterfaceEntryKey(InterfaceManagerTestUtil.tunnelInterfaceName); + bridgeInterfaceEntry = + new BridgeInterfaceEntryBuilder().setKey(bridgeInterfaceEntryKey) + .setInterfaceName(tunnelInterfaceEnabled.getName()).build(); + bridgeEntry = InterfaceManagerTestUtil.buildBridgeEntry(dpId, bridgeInterfaceEntry); + + when(dataBroker.newReadOnlyTransaction()).thenReturn(mockReadTx); + when(dataBroker.newWriteOnlyTransaction()).thenReturn(mockWriteTx); + } + + @Test + public void testAddTopologyStateInterface() + { + OptionalexpectedOvsdbBridgeAugmentation = Optional.of(bridgeNew); + Optional expectedBridgeEntry = Optional.of(bridgeEntry); + Optional expectedInterface = Optional.of(tunnelInterfaceEnabled); + + doReturn(Futures.immediateCheckedFuture(expectedInterface)).when(mockReadTx).read( + LogicalDatastoreType.CONFIGURATION, interfaceInstanceIdentifier); + doReturn(Futures.immediateCheckedFuture(expectedBridgeEntry)).when(mockReadTx).read( + LogicalDatastoreType.CONFIGURATION,bridgeEntryIid); + doReturn(Futures.immediateCheckedFuture(expectedOvsdbBridgeAugmentation)).when(mockReadTx).read( + LogicalDatastoreType.OPERATIONAL, bridgeIid); + + OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentation = new OvsdbBridgeAugmentationBuilder(bridgeNew); + ovsdbBridgeAugmentation.setDatapathId(DatapathId.getDefaultInstance("00:00:00:00:00:00:00:01")); + ovsdbBridgeAugmentation.setBridgeName(OvsdbBridgeName.getDefaultInstance("a")); + bridgeNew = ovsdbBridgeAugmentation.build(); + + addHelper.addPortToBridge(bridgeIid,bridgeNew,dataBroker); + + BigInteger ovsdbDpId = BigInteger.valueOf(1); + BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(ovsdbDpId); + InstanceIdentifier bridgeEntryId = + InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey); + BridgeRefEntryBuilder tunnelDpnBridgeEntryBuilder = + new BridgeRefEntryBuilder().setKey(bridgeRefEntryKey).setDpid(ovsdbDpId) + .setBridgeReference(new OvsdbBridgeRef(bridgeIid)); + + verify(mockWriteTx).put(LogicalDatastoreType.OPERATIONAL, bridgeEntryId, tunnelDpnBridgeEntryBuilder.build(), true); + } + + @Test + public void testDeleteTopologyStateInterface() + { + OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentation = new OvsdbBridgeAugmentationBuilder(bridgeOld); + ovsdbBridgeAugmentation.setDatapathId(DatapathId.getDefaultInstance("00:00:00:00:00:00:00:01")); + ovsdbBridgeAugmentation.setBridgeName(OvsdbBridgeName.getDefaultInstance("b")); + bridgeOld = ovsdbBridgeAugmentation.build(); + + removeHelper.removePortFromBridge(bridgeIid,bridgeOld,dataBroker); + + BigInteger ovsdbDpId = BigInteger.valueOf(1); + BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(ovsdbDpId); + InstanceIdentifier bridgeEntryId = + InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey); + + verify(mockWriteTx).delete(LogicalDatastoreType.OPERATIONAL,bridgeEntryId); + } +}