Add flows to forward OpenFlow traffic
Change-Id: Ic80a177d64c3bf50062ded264c62d66ad33ab0aa
Showing
1 changed file
with
56 additions
and
0 deletions
... | @@ -24,6 +24,8 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -24,6 +24,8 @@ import org.apache.felix.scr.annotations.Deactivate; |
24 | import org.apache.felix.scr.annotations.Reference; | 24 | import org.apache.felix.scr.annotations.Reference; |
25 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
26 | import org.apache.felix.scr.annotations.Service; | 26 | import org.apache.felix.scr.annotations.Service; |
27 | +import org.onlab.packet.Ethernet; | ||
28 | +import org.onlab.packet.IPv4; | ||
27 | import org.onlab.packet.VlanId; | 29 | import org.onlab.packet.VlanId; |
28 | import org.onosproject.core.ApplicationId; | 30 | import org.onosproject.core.ApplicationId; |
29 | import org.onosproject.core.CoreService; | 31 | import org.onosproject.core.CoreService; |
... | @@ -70,12 +72,23 @@ public class CordFabricManager implements FabricService { | ... | @@ -70,12 +72,23 @@ public class CordFabricManager implements FabricService { |
70 | 72 | ||
71 | private static final int PRIORITY = 1000; | 73 | private static final int PRIORITY = 1000; |
72 | 74 | ||
75 | + private short openflowPort = 6633; | ||
76 | + | ||
77 | + private DeviceId fabricDeviceId = DeviceId.deviceId("of:5e3e486e73000187"); | ||
78 | + | ||
79 | + private ConnectPoint oltConnectPoint = | ||
80 | + new ConnectPoint(fabricDeviceId, PortNumber.portNumber(2)); | ||
81 | + private ConnectPoint oltControllerConnectPoint = | ||
82 | + new ConnectPoint(fabricDeviceId, PortNumber.portNumber(1)); | ||
83 | + | ||
73 | private final Multimap<VlanId, ConnectPoint> vlans = HashMultimap.create(); | 84 | private final Multimap<VlanId, ConnectPoint> vlans = HashMultimap.create(); |
74 | 85 | ||
75 | @Activate | 86 | @Activate |
76 | public void activate() { | 87 | public void activate() { |
77 | appId = coreService.registerApplication("org.onosproject.cordfabric"); | 88 | appId = coreService.registerApplication("org.onosproject.cordfabric"); |
78 | 89 | ||
90 | + setupDefaultFlows(); | ||
91 | + | ||
79 | log.info("Started"); | 92 | log.info("Started"); |
80 | } | 93 | } |
81 | 94 | ||
... | @@ -84,6 +97,49 @@ public class CordFabricManager implements FabricService { | ... | @@ -84,6 +97,49 @@ public class CordFabricManager implements FabricService { |
84 | log.info("Stopped"); | 97 | log.info("Stopped"); |
85 | } | 98 | } |
86 | 99 | ||
100 | + private void setupDefaultFlows() { | ||
101 | + TrafficSelector toControllerS = DefaultTrafficSelector.builder() | ||
102 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
103 | + .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
104 | + .matchTcpDst(openflowPort) | ||
105 | + .build(); | ||
106 | + | ||
107 | + TrafficSelector fromControllerS = DefaultTrafficSelector.builder() | ||
108 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
109 | + .matchIPProtocol(IPv4.PROTOCOL_TCP) | ||
110 | + .matchTcpSrc(openflowPort) | ||
111 | + .build(); | ||
112 | + | ||
113 | + TrafficTreatment forwardToController = DefaultTrafficTreatment.builder() | ||
114 | + .setOutput(oltControllerConnectPoint.port()) | ||
115 | + .build(); | ||
116 | + | ||
117 | + TrafficTreatment forwardFromController = DefaultTrafficTreatment.builder() | ||
118 | + .setOutput(oltConnectPoint.port()) | ||
119 | + .build(); | ||
120 | + | ||
121 | + ForwardingObjective ofToController = DefaultForwardingObjective.builder() | ||
122 | + .fromApp(appId) | ||
123 | + .makePermanent() | ||
124 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
125 | + .withPriority(PRIORITY) | ||
126 | + .withSelector(toControllerS) | ||
127 | + .withTreatment(forwardToController) | ||
128 | + .add(); | ||
129 | + | ||
130 | + ForwardingObjective ofFromController = DefaultForwardingObjective.builder() | ||
131 | + .fromApp(appId) | ||
132 | + .makePermanent() | ||
133 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
134 | + .withPriority(PRIORITY) | ||
135 | + .withSelector(fromControllerS) | ||
136 | + .withTreatment(forwardFromController) | ||
137 | + .add(); | ||
138 | + | ||
139 | + flowObjectiveService.forward(fabricDeviceId, ofToController); | ||
140 | + flowObjectiveService.forward(fabricDeviceId, ofFromController); | ||
141 | + } | ||
142 | + | ||
87 | @Override | 143 | @Override |
88 | public void addVlan(FabricVlan vlan) { | 144 | public void addVlan(FabricVlan vlan) { |
89 | checkNotNull(vlan); | 145 | checkNotNull(vlan); | ... | ... |
-
Please register or login to post a comment