Updating Reactive forwarding to output unicast packet and added intents to wipe-out command
Showing
2 changed files
with
23 additions
and
7 deletions
1 | package org.onlab.onos.ifwd; | 1 | package org.onlab.onos.ifwd; |
2 | 2 | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
3 | import org.apache.felix.scr.annotations.Activate; | 5 | import org.apache.felix.scr.annotations.Activate; |
4 | import org.apache.felix.scr.annotations.Component; | 6 | import org.apache.felix.scr.annotations.Component; |
5 | import org.apache.felix.scr.annotations.Deactivate; | 7 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -17,7 +19,9 @@ import org.onlab.onos.net.host.HostService; | ... | @@ -17,7 +19,9 @@ import org.onlab.onos.net.host.HostService; |
17 | import org.onlab.onos.net.intent.HostToHostIntent; | 19 | import org.onlab.onos.net.intent.HostToHostIntent; |
18 | import org.onlab.onos.net.intent.IntentId; | 20 | import org.onlab.onos.net.intent.IntentId; |
19 | import org.onlab.onos.net.intent.IntentService; | 21 | import org.onlab.onos.net.intent.IntentService; |
22 | +import org.onlab.onos.net.packet.DefaultOutboundPacket; | ||
20 | import org.onlab.onos.net.packet.InboundPacket; | 23 | import org.onlab.onos.net.packet.InboundPacket; |
24 | +import org.onlab.onos.net.packet.OutboundPacket; | ||
21 | import org.onlab.onos.net.packet.PacketContext; | 25 | import org.onlab.onos.net.packet.PacketContext; |
22 | import org.onlab.onos.net.packet.PacketProcessor; | 26 | import org.onlab.onos.net.packet.PacketProcessor; |
23 | import org.onlab.onos.net.packet.PacketService; | 27 | import org.onlab.onos.net.packet.PacketService; |
... | @@ -25,17 +29,12 @@ import org.onlab.onos.net.topology.TopologyService; | ... | @@ -25,17 +29,12 @@ import org.onlab.onos.net.topology.TopologyService; |
25 | import org.onlab.packet.Ethernet; | 29 | import org.onlab.packet.Ethernet; |
26 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
27 | 31 | ||
28 | -import static org.slf4j.LoggerFactory.getLogger; | ||
29 | - | ||
30 | /** | 32 | /** |
31 | * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework. | 33 | * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework. |
32 | */ | 34 | */ |
33 | @Component(immediate = true) | 35 | @Component(immediate = true) |
34 | public class IntentReactiveForwarding { | 36 | public class IntentReactiveForwarding { |
35 | 37 | ||
36 | - private static final int TIMEOUT = 10; | ||
37 | - private static final int PRIORITY = 10; | ||
38 | - | ||
39 | private final Logger log = getLogger(getClass()); | 38 | private final Logger log = getLogger(getClass()); |
40 | 39 | ||
41 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 40 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -98,6 +97,7 @@ public class IntentReactiveForwarding { | ... | @@ -98,6 +97,7 @@ public class IntentReactiveForwarding { |
98 | 97 | ||
99 | // Otherwise forward and be done with it. | 98 | // Otherwise forward and be done with it. |
100 | setUpConnectivity(context, srcId, dstId); | 99 | setUpConnectivity(context, srcId, dstId); |
100 | + forwardPacketToDst(context, dst); | ||
101 | } | 101 | } |
102 | } | 102 | } |
103 | 103 | ||
... | @@ -117,6 +117,14 @@ public class IntentReactiveForwarding { | ... | @@ -117,6 +117,14 @@ public class IntentReactiveForwarding { |
117 | context.send(); | 117 | context.send(); |
118 | } | 118 | } |
119 | 119 | ||
120 | + private void forwardPacketToDst(PacketContext context, Host dst) { | ||
121 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(dst.location().port()).build(); | ||
122 | + OutboundPacket packet = new DefaultOutboundPacket(dst.location().deviceId(), | ||
123 | + treatment, context.inPacket().unparsed()); | ||
124 | + packetService.emit(packet); | ||
125 | + log.info("sending packet: {}", packet); | ||
126 | + } | ||
127 | + | ||
120 | // Install a rule forwarding the packet to the specified port. | 128 | // Install a rule forwarding the packet to the specified port. |
121 | private void setUpConnectivity(PacketContext context, HostId srcId, HostId dstId) { | 129 | private void setUpConnectivity(PacketContext context, HostId srcId, HostId dstId) { |
122 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); | 130 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); | ... | ... |
... | @@ -7,6 +7,9 @@ import org.onlab.onos.net.device.DeviceAdminService; | ... | @@ -7,6 +7,9 @@ import org.onlab.onos.net.device.DeviceAdminService; |
7 | import org.onlab.onos.net.device.DeviceService; | 7 | import org.onlab.onos.net.device.DeviceService; |
8 | import org.onlab.onos.net.host.HostAdminService; | 8 | import org.onlab.onos.net.host.HostAdminService; |
9 | import org.onlab.onos.net.host.HostService; | 9 | import org.onlab.onos.net.host.HostService; |
10 | +import org.onlab.onos.net.intent.Intent; | ||
11 | +import org.onlab.onos.net.intent.IntentService; | ||
12 | +import org.onlab.onos.net.intent.IntentState; | ||
10 | 13 | ||
11 | /** | 14 | /** |
12 | * Wipes-out the entire network information base, i.e. devices, links, hosts. | 15 | * Wipes-out the entire network information base, i.e. devices, links, hosts. |
... | @@ -28,7 +31,12 @@ public class WipeOutCommand extends ClustersListCommand { | ... | @@ -28,7 +31,12 @@ public class WipeOutCommand extends ClustersListCommand { |
28 | for (Host host : hostService.getHosts()) { | 31 | for (Host host : hostService.getHosts()) { |
29 | hostAdminService.removeHost(host.id()); | 32 | hostAdminService.removeHost(host.id()); |
30 | } | 33 | } |
31 | - } | ||
32 | - | ||
33 | 34 | ||
35 | + IntentService intentService = get(IntentService.class); | ||
36 | + for (Intent intent : intentService.getIntents()) { | ||
37 | + if (intentService.getIntentState(intent.getId()) == IntentState.INSTALLED) { | ||
38 | + intentService.withdraw(intent); | ||
39 | + } | ||
40 | + } | ||
41 | + } | ||
34 | } | 42 | } | ... | ... |
-
Please register or login to post a comment