Showing
1 changed file
with
18 additions
and
20 deletions
1 | package org.onlab.onos.fwd; | 1 | package org.onlab.onos.fwd; |
2 | 2 | ||
3 | -import static org.slf4j.LoggerFactory.getLogger; | ||
4 | - | ||
5 | -import java.util.Set; | ||
6 | - | ||
7 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
8 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; |
9 | import org.apache.felix.scr.annotations.Deactivate; | 5 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -31,6 +27,10 @@ import org.onlab.onos.net.topology.TopologyService; | ... | @@ -31,6 +27,10 @@ import org.onlab.onos.net.topology.TopologyService; |
31 | import org.onlab.packet.Ethernet; | 27 | import org.onlab.packet.Ethernet; |
32 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
33 | 29 | ||
30 | +import java.util.Set; | ||
31 | + | ||
32 | +import static org.slf4j.LoggerFactory.getLogger; | ||
33 | + | ||
34 | /** | 34 | /** |
35 | * Sample reactive forwarding application. | 35 | * Sample reactive forwarding application. |
36 | */ | 36 | */ |
... | @@ -81,7 +81,8 @@ public class ReactiveForwarding { | ... | @@ -81,7 +81,8 @@ public class ReactiveForwarding { |
81 | } | 81 | } |
82 | 82 | ||
83 | InboundPacket pkt = context.inPacket(); | 83 | InboundPacket pkt = context.inPacket(); |
84 | - HostId id = HostId.hostId(pkt.parsed().getDestinationMAC()); | 84 | + Ethernet ethPkt = pkt.parsed(); |
85 | + HostId id = HostId.hostId(ethPkt.getDestinationMAC()); | ||
85 | 86 | ||
86 | // Do we know who this is for? If not, flood and bail. | 87 | // Do we know who this is for? If not, flood and bail. |
87 | Host dst = hostService.getHost(id); | 88 | Host dst = hostService.getHost(id); |
... | @@ -100,7 +101,7 @@ public class ReactiveForwarding { | ... | @@ -100,7 +101,7 @@ public class ReactiveForwarding { |
100 | // Otherwise, get a set of paths that lead from here to the | 101 | // Otherwise, get a set of paths that lead from here to the |
101 | // destination edge switch. | 102 | // destination edge switch. |
102 | Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), | 103 | Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), |
103 | - context.inPacket().receivedFrom().deviceId(), | 104 | + pkt.receivedFrom().deviceId(), |
104 | dst.location().deviceId()); | 105 | dst.location().deviceId()); |
105 | if (paths.isEmpty()) { | 106 | if (paths.isEmpty()) { |
106 | // If there are no paths, flood and bail. | 107 | // If there are no paths, flood and bail. |
... | @@ -112,7 +113,9 @@ public class ReactiveForwarding { | ... | @@ -112,7 +113,9 @@ public class ReactiveForwarding { |
112 | // came from; if no such path, flood and bail. | 113 | // came from; if no such path, flood and bail. |
113 | Path path = pickForwardPath(paths, pkt.receivedFrom().port()); | 114 | Path path = pickForwardPath(paths, pkt.receivedFrom().port()); |
114 | if (path == null) { | 115 | if (path == null) { |
115 | - log.warn("Doh... don't know where to go..."); | 116 | + log.warn("Doh... don't know where to go... {} -> {} received on {}", |
117 | + ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), | ||
118 | + pkt.receivedFrom().port()); | ||
116 | flood(context); | 119 | flood(context); |
117 | return; | 120 | return; |
118 | } | 121 | } |
... | @@ -133,28 +136,28 @@ public class ReactiveForwarding { | ... | @@ -133,28 +136,28 @@ public class ReactiveForwarding { |
133 | return null; | 136 | return null; |
134 | } | 137 | } |
135 | 138 | ||
136 | - // Floods the specified packet. | 139 | + // Floods the specified packet if permissible. |
137 | private void flood(PacketContext context) { | 140 | private void flood(PacketContext context) { |
138 | if (topologyService.isBroadcastPoint(topologyService.currentTopology(), | 141 | if (topologyService.isBroadcastPoint(topologyService.currentTopology(), |
139 | context.inPacket().receivedFrom())) { | 142 | context.inPacket().receivedFrom())) { |
140 | - packetOutFlood(context); | 143 | + packetOut(context, PortNumber.FLOOD); |
141 | } else { | 144 | } else { |
142 | context.block(); | 145 | context.block(); |
143 | } | 146 | } |
144 | } | 147 | } |
145 | 148 | ||
146 | - //Floods a packet out | 149 | + // Sends a packet out the specified port. |
147 | - private void packetOutFlood(PacketContext context) { | 150 | + private void packetOut(PacketContext context, PortNumber portNumber) { |
148 | - context.treatmentBuilder().add(Instructions.createOutput(PortNumber.FLOOD)); | 151 | + context.treatmentBuilder().add(Instructions.createOutput(portNumber)); |
149 | context.send(); | 152 | context.send(); |
150 | } | 153 | } |
151 | 154 | ||
152 | // Install a rule forwarding the packet to the specified port. | 155 | // Install a rule forwarding the packet to the specified port. |
153 | private void installRule(PacketContext context, PortNumber portNumber) { | 156 | private void installRule(PacketContext context, PortNumber portNumber) { |
154 | - // we don't yet support bufferids in the flowservice so packet out and | 157 | + // We don't yet support bufferids in the flowservice so packet out first. |
155 | - // then install a flowmod. | 158 | + packetOut(context, portNumber); |
156 | - packetOutFlood(context); | ||
157 | 159 | ||
160 | + // Install the flow rule to handle this type of message from now on. | ||
158 | Ethernet inPkt = context.inPacket().parsed(); | 161 | Ethernet inPkt = context.inPacket().parsed(); |
159 | TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder(); | 162 | TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder(); |
160 | builder.add(Criteria.matchEthType(inPkt.getEtherType())) | 163 | builder.add(Criteria.matchEthType(inPkt.getEtherType())) |
... | @@ -169,11 +172,6 @@ public class ReactiveForwarding { | ... | @@ -169,11 +172,6 @@ public class ReactiveForwarding { |
169 | builder.build(), treat.build()); | 172 | builder.build(), treat.build()); |
170 | 173 | ||
171 | flowRuleService.applyFlowRules(f); | 174 | flowRuleService.applyFlowRules(f); |
172 | - | ||
173 | - // we don't yet support bufferids in the flowservice so packet out and | ||
174 | - // then install a flowmod. | ||
175 | - context.treatmentBuilder().add(Instructions.createOutput(portNumber)); | ||
176 | - context.send(); | ||
177 | } | 175 | } |
178 | 176 | ||
179 | } | 177 | } | ... | ... |
-
Please register or login to post a comment