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;
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;
+ }
}
/* 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);
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;
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<BridgeRefEntry> 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<BridgeEntry> bridgeEntryInstanceIdentifier =
InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey);
BridgeEntry bridgeEntry =
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;
OvsdbBridgeAugmentation bridgeOld, DataBroker dataBroker) {
List<ListenableFuture<Void>> 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<BridgeRefEntry> bridgeEntryId =
InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
t.delete(LogicalDatastoreType.OPERATIONAL, bridgeEntryId);
public static List<ListenableFuture<Void>> bindService(InstanceIdentifier<BoundServices> instanceIdentifier,
BoundServices boundServiceNew, DataBroker dataBroker) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
- WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
String interfaceName =
InstanceIdentifier.keyOf(instanceIdentifier.firstIdentifierOf(ServicesInfo.class)).getInterfaceName();
int vlanId = 0;
List<MatchInfo> 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;
}
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<MatchInfo> 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;
}
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> 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());
}
}
if (highestPriority < boundServiceOld.getServicePriority()) {
- FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, dataBroker, t);
+ FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t);
if (t != null) {
futures.add(t.submit());
}
List<MatchInfo> 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());
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<MatchInfo> 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());
}
}
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);
}
}
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;
return null;
}
- public static List<MatchInfo> getMatchInfoForVlanPortAtIngressTable(BigInteger dpId, long portNo, long vlanId) {
+ public static List<MatchInfo> getMatchInfoForVlanPortAtIngressTable(BigInteger dpId, long portNo, Interface iface) {
List<MatchInfo> 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}));
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<MatchInfo> matches, int lportTag, short tableId) {
List<Instruction> instructions = boundServiceNew.getAugmentation(StypeOpenflow.class).getInstruction();
int serviceInstructionsSize = instructions.size();
List<Instruction> instructionSet = new ArrayList<Instruction>();
+ 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;
}
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,
}
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();
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));
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<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
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;
FlowCapableNodeConnector fcNodeConnectorNew = null;
Interface vlanInterfaceEnabled = null;
Interface vlanInterfaceDisabled = null;
+ InterfaceParentEntryKey interfaceParentEntryKey = null;
IfIndexInterface IfindexInterface = null;
InstanceIdentifier<Interface> interfaceInstanceIdentifier = null;
InstanceIdentifier<FlowCapableNodeConnector> fcNodeConnectorId = null;
InstanceIdentifier<IfIndexInterface> ifIndexId =null;
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> interfaceStateIdentifier = null;
+ InstanceIdentifier<InterfaceParentEntry> 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;
OvsInterfaceStateAddHelper addHelper;
OvsInterfaceStateRemoveHelper removeHelper;
+ OvsInterfaceStateUpdateHelper updateHelper;
@Before
public void setUp() throws Exception {
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<String> lowerLayerIfList = new ArrayList<>();
lowerLayerIfList.add(nodeConnectorId.getValue());
.setIfIndex(100)
.setLowerLayerIf(lowerLayerIfList);
ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(InterfaceManagerTestUtil.interfaceName));
+
stateInterface = ifaceBuilder.build();
+
+ InterfaceParentEntryBuilder ifaceParentEntryBuilder = new InterfaceParentEntryBuilder();
+ List<InterfaceChildEntry> ifaceChildEntryList= new ArrayList<>();
+ interfaceParentEntry = ifaceParentEntryBuilder.setInterfaceChildEntry(ifaceChildEntryList).build();
+
when(dataBroker.newReadOnlyTransaction()).thenReturn(mockReadTx);
when(dataBroker.newWriteOnlyTransaction()).thenReturn(mockWriteTx);
}
verify(mockWriteTx).delete(LogicalDatastoreType.OPERATIONAL, ifIndexId);
}
+ @Test
+ public void testUpdateStateInterface(){
+
+ Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface>
+ expectedStateInterface = Optional.of(stateInterface);
+ Optional<InterfaceParentEntry>expectedParentEntry = 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
--- /dev/null
+/**
+ * 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);
+ InstanceIdentifier<OvsdbBridgeAugmentation>bridgeIid = null;
+ InstanceIdentifier<BridgeEntry> bridgeEntryIid = null;
+ OvsdbBridgeAugmentation bridgeNew;
+ OvsdbBridgeAugmentation bridgeOld;
+ BridgeEntry bridgeEntry = null;
+ ParentRefs parentRefs = null;
+ InstanceIdentifier<Interface> interfaceInstanceIdentifier = null;
+ Interface tunnelInterfaceEnabled = null;
+ BridgeInterfaceEntry bridgeInterfaceEntry;
+ BridgeInterfaceEntryKey bridgeInterfaceEntryKey;
+
+ @Mock DataBroker dataBroker;
+ @Mock ListenerRegistration<DataChangeListener> 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()
+ {
+ Optional<OvsdbBridgeAugmentation>expectedOvsdbBridgeAugmentation = Optional.of(bridgeNew);
+ Optional<BridgeEntry> expectedBridgeEntry = Optional.of(bridgeEntry);
+ Optional<Interface> 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<BridgeRefEntry> 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<BridgeRefEntry> bridgeEntryId =
+ InterfaceMetaUtils.getBridgeRefEntryIdentifier(bridgeRefEntryKey);
+
+ verify(mockWriteTx).delete(LogicalDatastoreType.OPERATIONAL,bridgeEntryId);
+ }
+}