Add flows to forward OpenFlow traffic
Change-Id: Ic80a177d64c3bf50062ded264c62d66ad33ab0aa
diff --git a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
index ca8501a..d45ae61 100644
--- a/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
+++ b/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java
@@ -24,6 +24,8 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.IPv4;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
@@ -70,12 +72,23 @@
private static final int PRIORITY = 1000;
+ private short openflowPort = 6633;
+
+ private DeviceId fabricDeviceId = DeviceId.deviceId("of:5e3e486e73000187");
+
+ private ConnectPoint oltConnectPoint =
+ new ConnectPoint(fabricDeviceId, PortNumber.portNumber(2));
+ private ConnectPoint oltControllerConnectPoint =
+ new ConnectPoint(fabricDeviceId, PortNumber.portNumber(1));
+
private final Multimap<VlanId, ConnectPoint> vlans = HashMultimap.create();
@Activate
public void activate() {
appId = coreService.registerApplication("org.onosproject.cordfabric");
+ setupDefaultFlows();
+
log.info("Started");
}
@@ -84,6 +97,49 @@
log.info("Stopped");
}
+ private void setupDefaultFlows() {
+ TrafficSelector toControllerS = DefaultTrafficSelector.builder()
+ .matchEthType(Ethernet.TYPE_IPV4)
+ .matchIPProtocol(IPv4.PROTOCOL_TCP)
+ .matchTcpDst(openflowPort)
+ .build();
+
+ TrafficSelector fromControllerS = DefaultTrafficSelector.builder()
+ .matchEthType(Ethernet.TYPE_IPV4)
+ .matchIPProtocol(IPv4.PROTOCOL_TCP)
+ .matchTcpSrc(openflowPort)
+ .build();
+
+ TrafficTreatment forwardToController = DefaultTrafficTreatment.builder()
+ .setOutput(oltControllerConnectPoint.port())
+ .build();
+
+ TrafficTreatment forwardFromController = DefaultTrafficTreatment.builder()
+ .setOutput(oltConnectPoint.port())
+ .build();
+
+ ForwardingObjective ofToController = DefaultForwardingObjective.builder()
+ .fromApp(appId)
+ .makePermanent()
+ .withFlag(ForwardingObjective.Flag.VERSATILE)
+ .withPriority(PRIORITY)
+ .withSelector(toControllerS)
+ .withTreatment(forwardToController)
+ .add();
+
+ ForwardingObjective ofFromController = DefaultForwardingObjective.builder()
+ .fromApp(appId)
+ .makePermanent()
+ .withFlag(ForwardingObjective.Flag.VERSATILE)
+ .withPriority(PRIORITY)
+ .withSelector(fromControllerS)
+ .withTreatment(forwardFromController)
+ .add();
+
+ flowObjectiveService.forward(fabricDeviceId, ofToController);
+ flowObjectiveService.forward(fabricDeviceId, ofFromController);
+ }
+
@Override
public void addVlan(FabricVlan vlan) {
checkNotNull(vlan);