From 248d01faaad4f5eca76fc72cba57e244be10d8a2 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Mon, 6 Jan 2014 04:20:20 -0800 Subject: [PATCH] Fix for Bug 271 Change-Id: I6a7335b467277ce18318bd24a2456ce1bd8c4b32 Signed-off-by: Ed Warnicke --- .../compatibility/FlowProgrammerAdapter.xtend | 64 ++++++++---------- .../FromSalConversionsUtils.java | 67 +++++++++++++------ .../sal/compatibility/MDFlowMapping.xtend | 22 ++++++ .../md-sal/model/model-flow-base/pom.xml | 5 ++ .../src/main/yang/match-types.yang | 5 +- .../manager/StatisticsUpdateCommiter.java | 4 +- 6 files changed, 106 insertions(+), 61 deletions(-) diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FlowProgrammerAdapter.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FlowProgrammerAdapter.xtend index e07fd6ddec..450c7f1f23 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FlowProgrammerAdapter.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FlowProgrammerAdapter.xtend @@ -35,7 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId -import static org.opendaylight.controller.sal.compatibility.MDFlowMapping.* +import static extension org.opendaylight.controller.sal.compatibility.MDFlowMapping.* import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.* import static extension org.opendaylight.controller.sal.compatibility.ToSalConversionsUtils.* @@ -54,54 +54,44 @@ class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, SalFlowLi private IPluginOutFlowProgrammerService flowProgrammerPublisher; override addFlow(Node node, Flow flow) { - val input = addFlowInput(node, flow); - writeFlow(input, new NodeKey(new NodeId(node.getNodeIDString())), new FlowKey(new FlowId(flow.getId()))); - return toStatus(true); + return addFlowAsync(node,flow,0) } override modifyFlow(Node node, Flow oldFlow, Flow newFlow) { - val input = updateFlowInput(node, oldFlow, newFlow); - val future = delegate.updateFlow(input); - try { - val result = future.get(); - return toStatus(result); - } catch (Exception e) { - return processException(e); - } + return modifyFlowAsync(node, oldFlow,newFlow,0) } override removeFlow(Node node, Flow flow) { - val input = removeFlowInput(node, flow); - val future = delegate.removeFlow(input); - - try { - val result = future.get(); - return toStatus(result); - } catch (Exception e) { - return processException(e); - } + return removeFlowAsync(node, flow,0); } override addFlowAsync(Node node, Flow flow, long rid) { - val input = addFlowInput(node, flow); - delegate.addFlow(input); - return new Status(StatusCode.SUCCESS); + writeFlow(flow.toMDFlow, new NodeKey(new NodeId(node.getNodeIDString()))); + return toStatus(true); } override modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow, long rid) { - val input = updateFlowInput(node, oldFlow, newFlow); - delegate.updateFlow(input); - return new Status(StatusCode.SUCCESS); + writeFlow(newFlow.toMDFlow, new NodeKey(new NodeId(node.getNodeIDString()))); + return toStatus(true); } - override removeFlowAsync(Node node, Flow flow, long rid) { - val input = removeFlowInput(node, flow); - delegate.removeFlow(input); - return new Status(StatusCode.SUCCESS); + override removeFlowAsync(Node node, Flow adflow, long rid) { + val flow = adflow.toMDFlow; + val modification = this._dataBrokerService.beginTransaction(); + val flowPath = InstanceIdentifier.builder(Nodes) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, new NodeKey(new NodeId(node.getNodeIDString()))) + .augmentation(FlowCapableNode) + .child(Table, new TableKey(flow.getTableId())) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow, new FlowKey(flow.id)) + .build; + modification.removeConfigurationData(flowPath); + val commitFuture = modification.commit(); + return toStatus(true); } override removeAllFlows(Node node) { - throw new UnsupportedOperationException("Not present in MD-SAL"); + // I know this looks like a copout... but its exactly what the legacy OFplugin did + return new Status(StatusCode.SUCCESS); } override syncSendBarrierMessage(Node node) { @@ -125,12 +115,14 @@ class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, SalFlowLi } - private def writeFlow(AddFlowInput flow, NodeKey nodeKey, FlowKey flowKey) { + private def writeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow flow, NodeKey nodeKey) { val modification = this._dataBrokerService.beginTransaction(); val flowPath = InstanceIdentifier.builder(Nodes) - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, nodeKey).augmentation(FlowCapableNode) - .child(Table, new TableKey(flow.getTableId())).child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow, flowKey).build(); - modification.putOperationalData(flowPath, flow); + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, nodeKey) + .augmentation(FlowCapableNode) + .child(Table, new TableKey(flow.getTableId())) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow, new FlowKey(flow.id)) + .build; modification.putConfigurationData(flowPath, flow); val commitFuture = modification.commit(); try { diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java index 8301da247a..eba4aa901b 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java @@ -12,6 +12,7 @@ import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; +import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.match.Match; import org.opendaylight.controller.sal.match.MatchField; import org.opendaylight.controller.sal.match.MatchType; @@ -26,6 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.addr import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp; @@ -83,6 +85,7 @@ public class FromSalConversionsUtils { targetBuilder.setVlanMatch(vlanMatch(sourceMatch)); targetBuilder.setLayer3Match(layer3Match(sourceMatch)); targetBuilder.setLayer4Match(layer4Match(sourceMatch)); + targetBuilder.setInPort(inPortMatch(sourceMatch)); return targetBuilder.build(); } @@ -90,6 +93,14 @@ public class FromSalConversionsUtils { } + private static NodeConnectorId inPortMatch(Match sourceMatch) { + MatchField inPort = sourceMatch.getField(MatchType.IN_PORT); + if(inPort != null && inPort.getValue() != null && (inPort.getValue() instanceof NodeConnector)) { + return new NodeConnectorId(((NodeConnector) inPort.getValue()).getNodeConnectorIdAsString()); + } + return null; + } + private static Layer4Match layer4Match(final Match sourceMatch) { MatchField nwProto = sourceMatch.getField(MatchType.NW_PROTO); Short nwProtocolSource = null; @@ -121,8 +132,10 @@ public class FromSalConversionsUtils { sctpMatchBuilder.setSctpDestinationPort(new PortNumber( destinationPort)); } - - return sctpMatchBuilder.build(); + if(sourcePort != null || destinationPort != null) { + return sctpMatchBuilder.build(); + } + return null; } private static Layer4Match Layer4MatchAsUdp(final Match sourceMatch) { @@ -140,8 +153,10 @@ public class FromSalConversionsUtils { udpMatchBuilder.setUdpDestinationPort(new PortNumber( destinationPort)); } - - return udpMatchBuilder.build(); + if(sourcePort != null || destinationPort != null) { + return udpMatchBuilder.build(); + } + return null; } private static Layer4Match Layer4MatchAsTcp(final Match sourceMatch) { @@ -158,8 +173,10 @@ public class FromSalConversionsUtils { tcpMatchBuilder.setTcpDestinationPort(new PortNumber( destinationPort)); } - - return tcpMatchBuilder.build(); + if(sourcePort != null || destinationPort != null) { + return tcpMatchBuilder.build(); + } + return null; } private static Integer transportPort(final Match sourceMatch, @@ -189,8 +206,10 @@ public class FromSalConversionsUtils { vlanMatchBuild.setVlanPcp(new VlanPcp((short) ((byte) vlanPriority .getValue()))); } - - return vlanMatchBuild.build(); + if((vlan != null && vlan.getValue() != null) || (vlanPriority != null && vlanPriority.getValue() != null)) { + return vlanMatchBuild.build(); + } + return null; } private static IpMatch ipMatch(final Match sourceMatch) { @@ -208,21 +227,24 @@ public class FromSalConversionsUtils { targetIpMatchBuild.setIpProtocol((short) ((byte) protocol .getValue())); } - - return targetIpMatchBuild.build(); - + if((networkTos != null && networkTos.getValue() != null) || (protocol != null && protocol.getValue() != null)) { + return targetIpMatchBuild.build(); + } + return null; } private static EthernetMatch ethernetMatch(final Match sourceMatch) { final EthernetMatchBuilder targetEthMatchBuild = new EthernetMatchBuilder(); - - EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder() - .setAddress(ethernetSourceAddress(sourceMatch)); - targetEthMatchBuild.setEthernetSource(ethSourBuild.build()); - - EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder() - .setAddress(ethernetDestAddress(sourceMatch)); - targetEthMatchBuild.setEthernetDestination(ethDestBuild.build()); + if(sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) { + EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder() + .setAddress(ethernetSourceAddress(sourceMatch)); + targetEthMatchBuild.setEthernetSource(ethSourBuild.build()); + } + if(sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null) { + EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder() + .setAddress(ethernetDestAddress(sourceMatch)); + targetEthMatchBuild.setEthernetDestination(ethDestBuild.build()); + } final MatchField dataLinkType = sourceMatch.getField(MatchType.DL_TYPE); if (dataLinkType != null && dataLinkType.getValue() != null) { @@ -232,7 +254,12 @@ public class FromSalConversionsUtils { .setType(etherType); targetEthMatchBuild.setEthernetType(ethType.build()); } - return targetEthMatchBuild.build(); + if((sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) || + (sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null)|| + dataLinkType != null ) { + return targetEthMatchBuild.build(); + } + return null; } private static MacAddress ethernetSourceAddress(final Match sourceMatch) { diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.xtend index 1c9d06388e..b0f6065bac 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.xtend +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.xtend @@ -105,6 +105,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.instruction.ApplyActionsCaseBuilder import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId public class MDFlowMapping { @@ -134,6 +135,27 @@ public class MDFlowMapping { } + public static def toMDFlow(Flow sourceFlow) { + if (sourceFlow == null) + throw new IllegalArgumentException(); + val it = new FlowBuilder(); + hardTimeout = sourceFlow.hardTimeout as int + idleTimeout = sourceFlow.idleTimeout as int + cookie = BigInteger.valueOf(sourceFlow.id) + priority = sourceFlow.priority as int + id = new FlowId(sourceFlow.id) + + val sourceActions = sourceFlow.actions; + val targetActions = new ArrayList(); + for (sourceAction : sourceActions) { + targetActions.add(sourceAction.toAction()); + } + instructions = targetActions.toApplyInstruction(); + match = sourceFlow.match.toMatch(); + tableId = new Integer(0).shortValue + return it.build(); + } + public static def Instructions toApplyInstruction(ArrayList actions) { val it = new InstructionsBuilder; val applyActions = new InstructionBuilder; diff --git a/opendaylight/md-sal/model/model-flow-base/pom.xml b/opendaylight/md-sal/model/model-flow-base/pom.xml index 13ffa3f910..1c21effd05 100644 --- a/opendaylight/md-sal/model/model-flow-base/pom.xml +++ b/opendaylight/md-sal/model/model-flow-base/pom.xml @@ -21,6 +21,11 @@ opendaylight-l2-types 2013.08.27.0 + + ${project.groupId} + model-inventory + ${project.version} + bundle diff --git a/opendaylight/md-sal/model/model-flow-base/src/main/yang/match-types.yang b/opendaylight/md-sal/model/model-flow-base/src/main/yang/match-types.yang index 1ed1b6827b..31736d2737 100644 --- a/opendaylight/md-sal/model/model-flow-base/src/main/yang/match-types.yang +++ b/opendaylight/md-sal/model/model-flow-base/src/main/yang/match-types.yang @@ -5,6 +5,7 @@ module opendaylight-match-types { import ietf-inet-types {prefix inet; revision-date "2010-09-24";} import ietf-yang-types {prefix yang; revision-date "2010-09-24";} import opendaylight-l2-types {prefix l2t;revision-date "2013-08-27";} + import opendaylight-inventory {prefix inv;revision-date "2013-08-19";} revision "2013-10-26" { description "Initial revision of macth types"; @@ -270,11 +271,11 @@ module opendaylight-match-types { grouping match { leaf in-port { - type uint32; + type inv:node-connector-id; } leaf in-phy-port { - type uint32; + type inv:node-connector-id; } container "metadata" { diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java index 30f98cedd3..aa6e99a03f 100644 --- a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java +++ b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java @@ -847,9 +847,7 @@ public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsList } if (storedFlow.getInPort()== null) { if (statsFlow.getInPort() != null) { - if(statsFlow.getInPort()!= 0){ - return false; - } + return false; } } else if(!storedFlow.getInPort().equals(statsFlow.getInPort())) { return false; -- 2.36.6