From: Gaurav Bhagwani Date: Tue, 3 Dec 2013 14:50:51 +0000 (+0530) Subject: Few Validations for Match/Actios in FRMUtil X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~266^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=6b78efe2abdbdac6d4c5b423d2b43c102b65ff7b;p=controller.git Few Validations for Match/Actios in FRMUtil Signed-off-by: Gaurav Bhagwani Change-Id: Ie533434b77303dcc48e678c795e939b80cbf9acc --- diff --git a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FRMUtil.java b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FRMUtil.java index ae6ce2f800..24bfc4fdf4 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FRMUtil.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FRMUtil.java @@ -5,7 +5,9 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType; import org.opendaylight.controller.sal.utils.IPProtocols; +import org.opendaylight.controller.sal.utils.NetUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; @@ -21,24 +23,26 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActions; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActions; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.Meter; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; public class FRMUtil { protected static final Logger logger = LoggerFactory.getLogger(FRMUtil.class); @@ -48,6 +52,10 @@ public class FRMUtil { ADD, DELETE, UPDATE, GET }; + private enum EtherIPType { + ANY, V4, V6; + }; + public static boolean isNameValid(String name) { // Name validation @@ -59,55 +67,134 @@ public class FRMUtil { } public static boolean validateMatch(Flow flow) { + EtherIPType etype = EtherIPType.ANY; + EtherIPType ipsrctype = EtherIPType.ANY; + EtherIPType ipdsttype = EtherIPType.ANY; + Match match = flow.getMatch(); if (match != null) { EthernetMatch ethernetmatch = match.getEthernetMatch(); IpMatch ipmatch = match.getIpMatch(); + Layer3Match layer3match = match.getLayer3Match(); VlanMatch vlanmatch = match.getVlanMatch(); match.getIcmpv4Match(); if (ethernetmatch != null) { if ((ethernetmatch.getEthernetSource() != null) - && !isL2AddressValid(ethernetmatch.getEthernetSource().toString())) { + && !isL2AddressValid(ethernetmatch.getEthernetSource().getAddress().getValue())) { - logger.error("Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", + logger.error("Ethernet source address is not valid. Example: 00:05:b9:7c:81:5f", ethernetmatch.getEthernetSource()); return false; } if ((ethernetmatch.getEthernetDestination() != null) - && !isL2AddressValid(ethernetmatch.getEthernetDestination().toString())) { - logger.error("Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", + && !isL2AddressValid(ethernetmatch.getEthernetDestination().getAddress().getValue())) { + logger.error("Ethernet destination address is not valid. Example: 00:05:b9:7c:81:5f", ethernetmatch.getEthernetDestination()); return false; } if (ethernetmatch.getEthernetType() != null) { - int type = Integer.decode(ethernetmatch.getEthernetType().toString()); + long type = ethernetmatch.getEthernetType().getType().getValue().longValue(); if ((type < 0) || (type > 0xffff)) { logger.error("Ethernet type is not valid"); return false; + } else { + if (type == 0x0800) { + etype = EtherIPType.V4; + } else if (type == 0x86dd) { + etype = EtherIPType.V6; + } + } + + } + } + + if (layer3match != null) { + if (layer3match instanceof Ipv4Match) { + if (((Ipv4Match) layer3match).getIpv4Source() != null) { + if (NetUtils.isIPv4AddressValid(((Ipv4Match) layer3match).getIpv4Source().getValue())) { + ipsrctype = EtherIPType.V4; + } else { + logger.error("IP source address is not valid"); + return false; + } + + } else if (((Ipv4Match) layer3match).getIpv4Destination() != null) { + if (NetUtils.isIPv4AddressValid(((Ipv4Match) layer3match).getIpv4Destination().getValue())) { + ipdsttype = EtherIPType.V4; + } else { + logger.error("IP Destination address is not valid"); + return false; + } + + } + } else if (layer3match instanceof Ipv6Match) { + if (((Ipv6Match) layer3match).getIpv6Source() != null) { + if (NetUtils.isIPv6AddressValid(((Ipv6Match) layer3match).getIpv6Source().getValue())) { + ipsrctype = EtherIPType.V6; + } else { + logger.error("IPv6 source address is not valid"); + return false; + } + + } else if (((Ipv6Match) layer3match).getIpv6Destination() != null) { + if (NetUtils.isIPv6AddressValid(((Ipv6Match) layer3match).getIpv6Destination().getValue())) { + ipdsttype = EtherIPType.V6; + } else { + logger.error("IPv6 Destination address is not valid"); + return false; + } + + } + + } + + if (etype != EtherIPType.ANY) { + if ((ipsrctype != EtherIPType.ANY) && (ipsrctype != etype)) { + logger.error("Type mismatch between Ethernet & Src IP"); + return false; + } + if ((ipdsttype != EtherIPType.ANY) && (ipdsttype != etype)) { + logger.error("Type mismatch between Ethernet & Dst IP"); + return false; + } + } + if (ipsrctype != ipdsttype) { + if (!((ipsrctype == EtherIPType.ANY) || (ipdsttype == EtherIPType.ANY))) { + logger.error("IP Src Dest Type mismatch"); + return false; } } - } else if (ipmatch != null) { - if (ipmatch.getIpProtocol() != null && isProtocolValid(ipmatch.getIpProtocol().toString())) { + } + + if (ipmatch != null) { + if (ipmatch.getIpProtocol() != null && !(isProtocolValid(ipmatch.getIpProtocol().toString()))) { logger.error("Protocol is not valid"); return false; } - } else if (vlanmatch != null) { - if (vlanmatch.getVlanId() != null && isVlanIdValid(vlanmatch.getVlanId().toString())) { + + } + + if (vlanmatch != null) { + if (vlanmatch.getVlanId() != null + && !(isVlanIdValid(vlanmatch.getVlanId().getVlanId().getValue().toString()))) { logger.error("Vlan ID is not in the range 0 - 4095"); return false; } - if (vlanmatch.getVlanPcp() != null && isVlanPriorityValid(vlanmatch.getVlanPcp().toString())) { + if (vlanmatch.getVlanPcp() != null + && !(isVlanPriorityValid(vlanmatch.getVlanPcp().getValue().toString()))) { logger.error("Vlan priority is not in the range 0 - 7"); return false; } } + } return true; + } public static boolean validateActions(List actions) { @@ -134,7 +221,24 @@ public class FRMUtil { return false; } if (outputnodeconnector != null) { - // TODO + if (!outputnodeconnector.getValue().equals(NodeConnectorIDType.ALL) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.CONTROLLER) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.HWPATH) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.ONEPK) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.ONEPK2OPENFLOW) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.ONEPK2PCEP) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.OPENFLOW) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.OPENFLOW2ONEPK) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.OPENFLOW2PCEP) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.PCEP) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.PCEP2ONEPK) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.PCEP2OPENFLOW) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.PRODUCTION) + || !outputnodeconnector.getValue().equals(NodeConnectorIDType.SWSTACK)) { + logger.error("Output Action: NodeConnector Type is not valid"); + return false; + } + } } else if (action instanceof PushMplsAction) { Integer ethertype = ((PushMplsAction) action).getEthernetType(); @@ -154,7 +258,7 @@ public class FRMUtil { logger.error("Ether Type is not valid for PushVlanAction"); return false; } - } else if (action instanceof SetDlDstAction || action instanceof SetDlSrcAction) { + } else if (action instanceof SetDlDstAction) { MacAddress address = ((SetDlDstAction) action).getAddress(); if (address != null && !isL2AddressValid(address.toString())) { logger.error("SetDlDstAction: Address not valid"); @@ -184,25 +288,26 @@ public class FRMUtil { } } else if (action instanceof SetVlanIdAction) { VlanId vlanid = ((SetVlanIdAction) action).getVlanId(); - if (vlanid != null && !isVlanIdValid(vlanid.toString())) { - logger.error("Vlan ID %s is not in the range 0 - 4095"); + if (vlanid != null && !isVlanIdValid(vlanid.getValue().toString())) { + logger.error("Vlan ID is not in the range 0 - 4095"); return false; } } else if (action instanceof SetVlanPcpAction) { VlanPcp vlanpcp = ((SetVlanPcpAction) action).getVlanPcp(); - if (vlanpcp != null && !isVlanPriorityValid(vlanpcp.toString())) { - logger.error("Vlan priority %s is not in the range 0 - 7"); + if (vlanpcp != null && !isVlanPriorityValid(vlanpcp.getValue().toString())) { + logger.error("Vlan priority is not in the range 0 - 7"); return false; } } } return true; + } public static boolean validateInstructions(Flow flow) { List instructionsList = new ArrayList<>(); Instructions instructions = flow.getInstructions(); - if( instructions == null ) { + if (instructions == null) { return false; } instructionsList = instructions.getInstruction(); diff --git a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java index 6aa0d5fc90..2710104fcf 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/forwardingrulesmanager/consumer/impl/FlowConsumerImpl.java @@ -29,19 +29,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; @@ -58,7 +50,8 @@ import org.slf4j.LoggerFactory; public class FlowConsumerImpl implements IForwardingRulesManager { protected static final Logger logger = LoggerFactory.getLogger(FlowConsumerImpl.class); - private final FlowEventListener flowEventListener = new FlowEventListener(); + // private final FlowEventListener flowEventListener = new + // FlowEventListener(); private Registration listener1Reg; private SalFlowService flowService; // private FlowDataListener listener; @@ -89,7 +82,6 @@ public class FlowConsumerImpl implements IForwardingRulesManager { if (null == flowService) { logger.error("Consumer SAL Service is down or NULL. FRM may not function as intended"); - System.out.println("Consumer SAL Service is down or NULL."); return; } @@ -104,15 +96,14 @@ public class FlowConsumerImpl implements IForwardingRulesManager { // } // For switch events - listener1Reg = FRMConsumerImpl.getNotificationService().registerNotificationListener(flowEventListener); + // listener1Reg = + // FRMConsumerImpl.getNotificationService().registerNotificationListener(flowEventListener); if (null == listener1Reg) { logger.error("Listener to listen on flow data modifcation events"); - System.out.println("Consumer SAL Service is down or NULL."); return; } // addFlowTest(); - System.out.println("-------------------------------------------------------------------"); commitHandler = new FlowDataCommitHandler(); FRMConsumerImpl.getDataProviderService().registerCommitHandler(path, commitHandler); clusterContainerService = (IClusterContainerServices) ServiceHelper.getGlobalInstance( @@ -163,9 +154,7 @@ public class FlowConsumerImpl implements IForwardingRulesManager { AddFlowInput firstMsg = input1.build(); if (null != flowService) { - System.out.println(flowService.toString()); - } else { - System.out.println("ConsumerFlowService is NULL"); + logger.error("ConsumerFlowService is NULL"); } @SuppressWarnings("unused") Future> result1 = flowService.addFlow(firstMsg); @@ -185,36 +174,42 @@ public class FlowConsumerImpl implements IForwardingRulesManager { private void addFlow(InstanceIdentifier path, Flow dataObject) { AddFlowInputBuilder input = new AddFlowInputBuilder(); - - List inst = (dataObject).getInstructions().getInstruction(); + input.setNode((dataObject).getNode()); input.setPriority((dataObject).getPriority()); input.setMatch((dataObject).getMatch()); input.setCookie((dataObject).getCookie()); input.setInstructions((dataObject).getInstructions()); - dataObject.getMatch().getLayer3Match(); - for (int i = 0; i < inst.size(); i++) { - System.out.println("i = " + i + inst.get(i).getInstruction().toString()); - System.out.println("i = " + i + inst.get(i).toString()); - } - - System.out.println("Instruction list" + (dataObject).getInstructions().getInstruction().toString()); + input.setBufferId(dataObject.getBufferId()); + input.setTableId(dataObject.getTableId()); + input.setOutPort(dataObject.getOutPort()); + input.setOutGroup(dataObject.getOutGroup()); + input.setIdleTimeout(dataObject.getIdleTimeout()); + input.setHardTimeout(dataObject.getHardTimeout()); + input.setFlowName(dataObject.getFlowName()); + input.setFlags(dataObject.getFlags()); + input.setCookieMask(dataObject.getCookieMask()); + input.setContainerName(dataObject.getContainerName()); + input.setBarrier(dataObject.isBarrier()); + input.setInstallHw(dataObject.isInstallHw()); + input.setStrict(dataObject.isStrict()); // updating the staticflow cache /* - * Commented out... as in many other places... use of ClusteringServices is breaking things - * insufficient time to debug - Integer ordinal = staticFlowsOrdinal.get(0); - staticFlowsOrdinal.put(0, ++ordinal); - staticFlows.put(ordinal, dataObject); - */ + * Commented out... as in many other places... use of ClusteringServices + * is breaking things insufficient time to debug Integer ordinal = + * staticFlowsOrdinal.get(0); staticFlowsOrdinal.put(0, ++ordinal); + * staticFlows.put(ordinal, dataObject); + */ // We send flow to the sounthbound plugin + flowService.addFlow(input.build()); + /* - * Commented out as this will also break due to improper use of ClusteringServices - updateLocalDatabase((NodeFlow) dataObject, true); - */ + * Commented out as this will also break due to improper use of + * ClusteringServices updateLocalDatabase((NodeFlow) dataObject, true); + */ } /** @@ -226,34 +221,39 @@ public class FlowConsumerImpl implements IForwardingRulesManager { private void removeFlow(InstanceIdentifier path, Flow dataObject) { RemoveFlowInputBuilder input = new RemoveFlowInputBuilder(); - List inst = (dataObject).getInstructions().getInstruction(); input.setNode((dataObject).getNode()); input.setPriority((dataObject).getPriority()); input.setMatch((dataObject).getMatch()); input.setCookie((dataObject).getCookie()); input.setInstructions((dataObject).getInstructions()); - dataObject.getMatch().getLayer3Match(); - for (int i = 0; i < inst.size(); i++) { - System.out.println("i = " + i + inst.get(i).getInstruction().toString()); - System.out.println("i = " + i + inst.get(i).toString()); - } - - System.out.println("Instruction list" + (dataObject).getInstructions().getInstruction().toString()); - + input.setBufferId(dataObject.getBufferId()); + input.setTableId(dataObject.getTableId()); + input.setOutPort(dataObject.getOutPort()); + input.setOutGroup(dataObject.getOutGroup()); + input.setIdleTimeout(dataObject.getIdleTimeout()); + input.setHardTimeout(dataObject.getHardTimeout()); + input.setFlowName(dataObject.getFlowName()); + input.setFlags(dataObject.getFlags()); + input.setCookieMask(dataObject.getCookieMask()); + input.setContainerName(dataObject.getContainerName()); + input.setBarrier(dataObject.isBarrier()); + input.setInstallHw(dataObject.isInstallHw()); + input.setStrict(dataObject.isStrict()); // updating the staticflow cache /* - * Commented out due to problems caused by improper use of ClusteringServices - Integer ordinal = staticFlowsOrdinal.get(0); - staticFlowsOrdinal.put(0, ++ordinal); - staticFlows.put(ordinal, dataObject); - */ + * Commented out due to problems caused by improper use of + * ClusteringServices Integer ordinal = staticFlowsOrdinal.get(0); + * staticFlowsOrdinal.put(0, ++ordinal); staticFlows.put(ordinal, + * dataObject); + */ // We send flow to the sounthbound plugin flowService.removeFlow(input.build()); + /* - * Commented out due to problems caused by improper use of ClusteringServices - updateLocalDatabase((NodeFlow) dataObject, false); - */ + * Commented out due to problems caused by improper use of + * ClusteringServices updateLocalDatabase((NodeFlow) dataObject, false); + */ } /** @@ -272,52 +272,71 @@ public class FlowConsumerImpl implements IForwardingRulesManager { // updating the staticflow cache /* - * Commented out due to problems caused by improper use of ClusteringServices. - Integer ordinal = staticFlowsOrdinal.get(0); - staticFlowsOrdinal.put(0, ++ordinal); - staticFlows.put(ordinal, dataObject); - */ + * Commented out due to problems caused by improper use of + * ClusteringServices. Integer ordinal = staticFlowsOrdinal.get(0); + * staticFlowsOrdinal.put(0, ++ordinal); staticFlows.put(ordinal, + * dataObject); + */ // We send flow to the sounthbound plugin flowService.updateFlow(input.build()); + /* - * Commented out due to problems caused by improper use of ClusteringServices. - updateLocalDatabase((NodeFlow) dataObject, true); - */ + * Commented out due to problems caused by improper use of + * ClusteringServices. updateLocalDatabase((NodeFlow) dataObject, true); + */ } @SuppressWarnings("unchecked") private void commitToPlugin(internalTransaction transaction) { - Set, DataObject>> createdEntries = transaction.getModification().getCreatedConfigurationData().entrySet(); + Set, DataObject>> createdEntries = transaction.getModification() + .getCreatedConfigurationData().entrySet(); /* - * This little dance is because updatedEntries contains both created and modified entries - * The reason I created a new HashSet is because the collections we are returned are immutable. + * This little dance is because updatedEntries contains both created and + * modified entries The reason I created a new HashSet is because the + * collections we are returned are immutable. */ Set, DataObject>> updatedEntries = new HashSet, DataObject>>(); updatedEntries.addAll(transaction.getModification().getUpdatedConfigurationData().entrySet()); updatedEntries.removeAll(createdEntries); - Set> removeEntriesInstanceIdentifiers = transaction.getModification().getRemovedConfigurationData(); + Set> removeEntriesInstanceIdentifiers = transaction.getModification() + .getRemovedConfigurationData(); transaction.getModification().getOriginalConfigurationData(); for (Entry, DataObject> entry : createdEntries) { - if(entry.getValue() instanceof Flow) { - System.out.println("Coming add cc in FlowDatacommitHandler"); + if (entry.getValue() instanceof Flow) { + logger.debug("Coming add cc in FlowDatacommitHandler"); + Flow flow = (Flow) entry.getValue(); + boolean status = validate(flow); + if (!status) { + return; + } addFlow(entry.getKey(), (Flow) entry.getValue()); } } for (@SuppressWarnings("unused") Entry, DataObject> entry : updatedEntries) { - if(entry.getValue() instanceof Flow) { - System.out.println("Coming update cc in FlowDatacommitHandler"); + if (entry.getValue() instanceof Flow) { + logger.debug("Coming update cc in FlowDatacommitHandler"); + Flow flow = (Flow) entry.getValue(); + boolean status = validate(flow); + if (!status) { + return; + } updateFlow(entry.getKey(), (Flow) entry.getValue()); } } - for (InstanceIdentifier instanceId : removeEntriesInstanceIdentifiers ) { + for (InstanceIdentifier instanceId : removeEntriesInstanceIdentifiers) { DataObject removeValue = transaction.getModification().getOriginalConfigurationData().get(instanceId); - if(removeValue instanceof Flow) { - System.out.println("Coming remove cc in FlowDatacommitHandler"); + if (removeValue instanceof Flow) { + logger.debug("Coming remove cc in FlowDatacommitHandler"); + Flow flow = (Flow) removeValue; + boolean status = validate(flow); + if (!status) { + return; + } removeFlow(instanceId, (Flow) removeValue); } @@ -331,7 +350,7 @@ public class FlowConsumerImpl implements IForwardingRulesManager { @Override public DataCommitTransaction requestCommit(DataModification, DataObject> modification) { // We should verify transaction - System.out.println("Coming in FlowDatacommitHandler"); + logger.debug("Coming in FlowDatacommitHandler"); internalTransaction transaction = new internalTransaction(modification); transaction.prepareUpdate(); return transaction; @@ -364,44 +383,6 @@ public class FlowConsumerImpl implements IForwardingRulesManager { Set, DataObject>> puts = modification.getUpdatedConfigurationData().entrySet(); for (Entry, DataObject> entry : puts) { - - // validating the DataObject - DataObject value = entry.getValue(); - if(value instanceof Flow ) { - Flow flow = (Flow)value; - boolean status = validate(flow); - if (!status) { - return; - } - // Presence check - /* - * This is breaking due to some improper use of caches... - * - if (flowEntryExists(flow)) { - String error = "Entry with this name on specified table already exists"; - logger.warn("Entry with this name on specified table already exists: {}", entry); - logger.error(error); - return; - } - if (originalSwView.containsKey(entry)) { - logger.warn("Operation Rejected: A flow with same match and priority exists on the target node"); - logger.trace("Aborting to install {}", entry); - continue; - } - */ - if (!FRMUtil.validateMatch(flow)) { - logger.error("Not a valid Match"); - return; - } - if (!FRMUtil.validateInstructions(flow)) { - logger.error("Not a valid Instruction"); - return; - } - /* - * Commented out due to Clustering Services issues - * preparePutEntry(entry.getKey(), flow); - */ - } } // removals = modification.getRemovedConfigurationData(); @@ -419,11 +400,9 @@ public class FlowConsumerImpl implements IForwardingRulesManager { Flow original = originalSwView.get(key); if (original != null) { // It is update for us - System.out.println("Coming update in FlowDatacommitHandler"); updates.put(key, flow); } else { // It is addition for us - System.out.println("Coming add in FlowDatacommitHandler"); additions.put(key, flow); } } @@ -438,7 +417,7 @@ public class FlowConsumerImpl implements IForwardingRulesManager { commitToPlugin(this); // We return true if internal transaction is successful. // return Rpcs.getRpcResult(true, null, Collections.emptySet()); - return Rpcs.getRpcResult(true, null, Collections.emptySet()); + return Rpcs.getRpcResult(true, null, Collections. emptySet()); } /** @@ -451,43 +430,10 @@ public class FlowConsumerImpl implements IForwardingRulesManager { // NOOP - we did not modified any internal state during // requestCommit phase // return Rpcs.getRpcResult(true, null, Collections.emptySet()); - return Rpcs.getRpcResult(true, null, Collections.emptySet()); + return Rpcs.getRpcResult(true, null, Collections. emptySet()); } - public boolean validate(Flow flow) { - - String msg = ""; // Specific part of warn/error log - - boolean result = true; - // flow Name validation - if (flow.getFlowName() == null || flow.getFlowName().trim().isEmpty() - || !flow.getFlowName().matches(NAMEREGEX)) { - msg = "Invalid Flow name"; - result = false; - } - // Node Validation - if (result == true && flow.getNode() == null) { - msg = "Node is null"; - result = false; - } - - // TODO: Validate we are seeking to program a flow against a valid Node - - if (result == true && flow.getPriority() != null) { - if (flow.getPriority() < 0 || flow.getPriority() > 65535) { - msg = String.format("priority %s is not in the range 0 - 65535", - flow.getPriority()); - result = false; - } - } - if (result == false) { - logger.warn("Invalid Configuration for flow {}. The failure is {}",flow,msg); - logger.error("Invalid Configuration ({})",msg); - } - return result; - } - private boolean flowEntryExists(Flow flow) { // Flow name has to be unique on per table id basis for (ConcurrentMap.Entry entry : originalSwView.entrySet()) { @@ -500,47 +446,6 @@ public class FlowConsumerImpl implements IForwardingRulesManager { } } - final class FlowEventListener implements SalFlowListener { - - List addedFlows = new ArrayList<>(); - List removedFlows = new ArrayList<>(); - List updatedFlows = new ArrayList<>(); - - @Override - public void onFlowAdded(FlowAdded notification) { - System.out.println("added flow.........................."); - addedFlows.add(notification); - } - - @Override - public void onFlowRemoved(FlowRemoved notification) { - removedFlows.add(notification); - }; - - @Override - public void onFlowUpdated(FlowUpdated notification) { - updatedFlows.add(notification); - } - - @Override - public void onSwitchFlowRemoved(SwitchFlowRemoved notification) { - // TODO - } - - @Override - public void onNodeErrorNotification(NodeErrorNotification notification) { - // TODO Auto-generated method stub - - } - - @Override - public void onNodeExperimenterErrorNotification(NodeExperimenterErrorNotification notification) { - // TODO Auto-generated method stub - - }; - - } - // Commented out DataChangeListene - to be used by Stats // final class FlowDataListener implements DataChangeListener { @@ -580,6 +485,60 @@ public class FlowConsumerImpl implements IForwardingRulesManager { // } // } + public boolean validate(Flow flow) { + + String msg = ""; // Specific part of warn/error log + + boolean result = true; + // flow Name validation + if (flow.getFlowName() == null || flow.getFlowName().trim().isEmpty() || !flow.getFlowName().matches(NAMEREGEX)) { + msg = "Invalid Flow name"; + result = false; + } + // Node Validation + if (result == true && flow.getNode() == null) { + msg = "Node is null"; + result = false; + } + + // TODO: Validate we are seeking to program a flow against a valid + // Node + + if (result == true && flow.getPriority() != null) { + if (flow.getPriority() < 0 || flow.getPriority() > 65535) { + msg = String.format("priority %s is not in the range 0 - 65535", flow.getPriority()); + result = false; + } + } + + // Presence check + /* + * This is breaking due to some improper use of caches... + * + * if (flowEntryExists(flow)) { String error = + * "Entry with this name on specified table already exists"; + * logger.warn( + * "Entry with this name on specified table already exists: {}" , + * entry); logger.error(error); return; } if + * (originalSwView.containsKey(entry)) { logger.warn( + * "Operation Rejected: A flow with same match and priority exists on the target node" + * ); logger.trace("Aborting to install {}", entry); continue; } + */ + if (!FRMUtil.validateMatch(flow)) { + logger.error("Not a valid Match"); + result = false; + } + if (!FRMUtil.validateInstructions(flow)) { + logger.error("Not a valid Instruction"); + result = false; + } + if (result == false) { + logger.warn("Invalid Configuration for flow {}. The failure is {}", flow, msg); + logger.error("Invalid Configuration ({})", msg); + } + return result; + } + private static void updateLocalDatabase(NodeFlow entry, boolean add) { updateSwViewes(entry, add);