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.*
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) {
}
- 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 {
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;
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;
targetBuilder.setVlanMatch(vlanMatch(sourceMatch));
targetBuilder.setLayer3Match(layer3Match(sourceMatch));
targetBuilder.setLayer4Match(layer4Match(sourceMatch));
+ targetBuilder.setInPort(inPortMatch(sourceMatch));
return targetBuilder.build();
}
}
+ 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;
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) {
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) {
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,
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) {
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) {
.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) {
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 {
}
+ 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<Action>();
+ 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<Action> actions) {
val it = new InstructionsBuilder;
val applyActions = new InstructionBuilder;
<artifactId>opendaylight-l2-types</artifactId>
<version>2013.08.27.0</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>model-inventory</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<packaging>bundle</packaging>
</project>
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";
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" {
}
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;