import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
-import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
-import org.opendaylight.vpnservice.mdsalutil.MatchFieldType;
-import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
-import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
+import org.opendaylight.vpnservice.mdsalutil.*;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
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;
public static NodeConnectorId getNodeConnectorIdFromInterface(Interface iface, DataBroker dataBroker) {
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(iface.getName(), dataBroker);
- List<String> ofportIds = ifState.getLowerLayerIf();
- return new NodeConnectorId(ofportIds.get(0));
+ if(ifState != null) {
+ List<String> ofportIds = ifState.getLowerLayerIf();
+ return new NodeConnectorId(ofportIds.get(0));
+ }
+ 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, 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, iface.getName(), boundServiceNew);
StypeOpenflow stypeOpenflow = boundServiceNew.getAugmentation(StypeOpenflow.class);
- Flow ingressFlow = MDSALUtil.buildFlowNew(tableId, serviceRef,
+ Flow ingressFlow = MDSALUtil.buildFlowNew(tableId, flowRef,
stypeOpenflow.getFlowPriority(), serviceRef, 0, 0,
stypeOpenflow.getFlowCookie(), matches, instructionSet);
- installFlow(dpId, ingressFlow, dataBroker, t);
+ installFlow(dpId, ingressFlow, t);
}
- private static void installFlow(BigInteger dpId, Flow flow, DataBroker dataBroker, WriteTransaction t) {
+ public static void installFlow(BigInteger dpId, Flow flow, WriteTransaction t) {
FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
Node nodeDpn = buildInventoryDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
t.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
}
+ public static void removeFlow(String flowRef, BigInteger dpId, WriteTransaction t) {
+ LOG.debug("Removing Ingress Flows");
+ 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)
+ .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build();
+
+ t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
+ }
+
private static Node buildInventoryDpnNode(BigInteger dpnId) {
NodeId nodeId = new NodeId("openflow:" + dpnId);
Node nodeDpn = new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build();
}
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();
}
// build the flow and install it
- Flow ingressFlow = MDSALUtil.buildFlowNew(stypeOpenFlow.getDispatcherTableId(), serviceRef,
+ String flowRef = getFlowRef(dpId, iface.getName(), boundService);
+ Flow ingressFlow = MDSALUtil.buildFlowNew(stypeOpenFlow.getDispatcherTableId(), flowRef,
boundService.getServicePriority(), serviceRef, 0, 0, stypeOpenFlow.getFlowCookie(), matches, instructions);
- installFlow(dpId, ingressFlow, dataBroker, t);
+ 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 = iface.getName() + serviceOld.getServicePriority() +
- serviceOld.getServiceName() + IfmConstants.VLAN_INTERFACE_INGRESS_TABLE;
+ String flowKeyStr = getFlowRef(dpId, iface.getName(), serviceOld);
FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr));
Node nodeDpn = buildInventoryDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
- .child(Table.class, new TableKey(IfmConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build();
+ .child(Table.class, new TableKey(NwConstants.VLAN_INTERFACE_INGRESS_TABLE)).child(Flow.class, flowKey).build();
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)
t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
- public static String getInterfaceRefInfo(String dpId, String portName) {
- String portRefInfo = "";
- if (!"".equals(dpId)) {
- portRefInfo = dpId.toString() + ":";
- }
- portRefInfo = portRefInfo + portName;
- return portRefInfo;
+ private static String getFlowRef(BigInteger dpnId, String iface, BoundServices service) {
+ return new StringBuffer().append(dpnId).append( NwConstants.VLAN_INTERFACE_INGRESS_TABLE).append(NwConstants.FLOWID_SEPARATOR)
+ .append(iface).append(NwConstants.FLOWID_SEPARATOR).append(service.getServiceName()).append(NwConstants.FLOWID_SEPARATOR)
+ .append(service.getServicePriority()).toString();
}
}
\ No newline at end of file