Showing
11 changed files
with
162 additions
and
34 deletions
... | @@ -74,13 +74,12 @@ public class ReactiveForwarding { | ... | @@ -74,13 +74,12 @@ public class ReactiveForwarding { |
74 | 74 | ||
75 | @Override | 75 | @Override |
76 | public void process(PacketContext context) { | 76 | public void process(PacketContext context) { |
77 | - /* | 77 | + // Stop processing if the packet has been handled, since we |
78 | - * stop processing if the packet has been handled, | 78 | + // can't do any more to it. |
79 | - * we can't do any more to it | ||
80 | - */ | ||
81 | if (context.isHandled()) { | 79 | if (context.isHandled()) { |
82 | return; | 80 | return; |
83 | } | 81 | } |
82 | + | ||
84 | InboundPacket pkt = context.inPacket(); | 83 | InboundPacket pkt = context.inPacket(); |
85 | HostId id = HostId.hostId(pkt.parsed().getDestinationMAC()); | 84 | HostId id = HostId.hostId(pkt.parsed().getDestinationMAC()); |
86 | 85 | ||
... | @@ -100,10 +99,9 @@ public class ReactiveForwarding { | ... | @@ -100,10 +99,9 @@ public class ReactiveForwarding { |
100 | 99 | ||
101 | // Otherwise, get a set of paths that lead from here to the | 100 | // Otherwise, get a set of paths that lead from here to the |
102 | // destination edge switch. | 101 | // destination edge switch. |
103 | - | ||
104 | Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), | 102 | Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), |
105 | - context.inPacket().receivedFrom().deviceId(), | 103 | + context.inPacket().receivedFrom().deviceId(), |
106 | - dst.location().deviceId()); | 104 | + dst.location().deviceId()); |
107 | if (paths.isEmpty()) { | 105 | if (paths.isEmpty()) { |
108 | // If there are no paths, flood and bail. | 106 | // If there are no paths, flood and bail. |
109 | flood(context); | 107 | flood(context); |
... | @@ -137,9 +135,8 @@ public class ReactiveForwarding { | ... | @@ -137,9 +135,8 @@ public class ReactiveForwarding { |
137 | 135 | ||
138 | // Floods the specified packet. | 136 | // Floods the specified packet. |
139 | private void flood(PacketContext context) { | 137 | private void flood(PacketContext context) { |
140 | - boolean canBcast = topologyService.isBroadcastPoint(topologyService.currentTopology(), | 138 | + if (topologyService.isBroadcastPoint(topologyService.currentTopology(), |
141 | - context.inPacket().receivedFrom()); | 139 | + context.inPacket().receivedFrom())) { |
142 | - if (canBcast) { | ||
143 | packetOutFlood(context); | 140 | packetOutFlood(context); |
144 | } else { | 141 | } else { |
145 | context.block(); | 142 | context.block(); |
... | @@ -154,27 +151,25 @@ public class ReactiveForwarding { | ... | @@ -154,27 +151,25 @@ public class ReactiveForwarding { |
154 | 151 | ||
155 | // Install a rule forwarding the packet to the specified port. | 152 | // Install a rule forwarding the packet to the specified port. |
156 | private void installRule(PacketContext context, PortNumber portNumber) { | 153 | private void installRule(PacketContext context, PortNumber portNumber) { |
157 | - // we don't yet support bufferids in the flowservice so packet out and | ||
158 | - // then install a flowmod. | ||
159 | - context.treatmentBuilder().add(Instructions.createOutput(portNumber)); | ||
160 | - context.send(); | ||
161 | - | ||
162 | - | ||
163 | Ethernet inPkt = context.inPacket().parsed(); | 154 | Ethernet inPkt = context.inPacket().parsed(); |
164 | TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder(); | 155 | TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder(); |
165 | builder.add(Criteria.matchEthType(inPkt.getEtherType())) | 156 | builder.add(Criteria.matchEthType(inPkt.getEtherType())) |
166 | - .add(Criteria.matchEthSrc(inPkt.getSourceMAC())) | 157 | + .add(Criteria.matchEthSrc(inPkt.getSourceMAC())) |
167 | - .add(Criteria.matchEthDst(inPkt.getDestinationMAC())) | 158 | + .add(Criteria.matchEthDst(inPkt.getDestinationMAC())) |
168 | - .add(Criteria.matchInPort(context.inPacket().receivedFrom().port())); | 159 | + .add(Criteria.matchInPort(context.inPacket().receivedFrom().port())); |
169 | 160 | ||
170 | TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder(); | 161 | TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder(); |
171 | treat.add(Instructions.createOutput(portNumber)); | 162 | treat.add(Instructions.createOutput(portNumber)); |
172 | 163 | ||
173 | FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), | 164 | FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), |
174 | - builder.build(), treat.build()); | 165 | + builder.build(), treat.build()); |
175 | 166 | ||
176 | flowRuleService.applyFlowRules(f); | 167 | flowRuleService.applyFlowRules(f); |
177 | 168 | ||
169 | + // we don't yet support bufferids in the flowservice so packet out and | ||
170 | + // then install a flowmod. | ||
171 | + context.treatmentBuilder().add(Instructions.createOutput(portNumber)); | ||
172 | + context.send(); | ||
178 | } | 173 | } |
179 | 174 | ||
180 | } | 175 | } | ... | ... |
1 | /** | 1 | /** |
2 | * Core subsystem for processing inbound packets and emitting outbound packets. | 2 | * Core subsystem for processing inbound packets and emitting outbound packets. |
3 | + * Processing of inbound packets is always in the local context only, but | ||
4 | + * emitting outbound packets allows for cluster-wide operation. | ||
3 | */ | 5 | */ |
4 | package org.onlab.onos.net.trivial.packet.impl; | 6 | package org.onlab.onos.net.trivial.packet.impl; | ... | ... |
... | @@ -142,6 +142,15 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -142,6 +142,15 @@ public class DefaultTopology extends AbstractModel implements Topology { |
142 | return clusters.get(clusterId); | 142 | return clusters.get(clusterId); |
143 | } | 143 | } |
144 | 144 | ||
145 | + /** | ||
146 | + * Returns the topology cluster that contains the given device. | ||
147 | + * | ||
148 | + * @param deviceId device identifier | ||
149 | + * @return topology cluster | ||
150 | + */ | ||
151 | + TopologyCluster getCluster(DeviceId deviceId) { | ||
152 | + return clustersByDevice.get(deviceId); | ||
153 | + } | ||
145 | 154 | ||
146 | /** | 155 | /** |
147 | * Returns the set of cluster devices. | 156 | * Returns the set of cluster devices. |
... | @@ -174,13 +183,13 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -174,13 +183,13 @@ public class DefaultTopology extends AbstractModel implements Topology { |
174 | } | 183 | } |
175 | 184 | ||
176 | /** | 185 | /** |
177 | - * Indicates whether the given point is part of a broadcast tree. | 186 | + * Indicates whether the given point is part of a broadcast set. |
178 | * | 187 | * |
179 | * @param connectPoint connection point | 188 | * @param connectPoint connection point |
180 | - * @return true if in broadcast tree | 189 | + * @return true if in broadcast set |
181 | */ | 190 | */ |
182 | - boolean isInBroadcastTree(ConnectPoint connectPoint) { | 191 | + boolean isBroadcastPoint(ConnectPoint connectPoint) { |
183 | - // Any non-infrastructure, i.e. edge points are assumed to be OK | 192 | + // Any non-infrastructure, i.e. edge points are assumed to be OK. |
184 | if (!isInfrastructure(connectPoint)) { | 193 | if (!isInfrastructure(connectPoint)) { |
185 | return true; | 194 | return true; |
186 | } | 195 | } |
... | @@ -191,13 +200,23 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -191,13 +200,23 @@ public class DefaultTopology extends AbstractModel implements Topology { |
191 | throw new IllegalArgumentException("No cluster found for device " + connectPoint.deviceId()); | 200 | throw new IllegalArgumentException("No cluster found for device " + connectPoint.deviceId()); |
192 | } | 201 | } |
193 | 202 | ||
194 | - // If the broadcast tree is null or empty, or if the point explicitly | 203 | + // If the broadcast set is null or empty, or if the point explicitly |
195 | - // belongs to the broadcast tree points, return true; | 204 | + // belongs to it, return true; |
196 | Set<ConnectPoint> points = broadcastSets.get(cluster.id()); | 205 | Set<ConnectPoint> points = broadcastSets.get(cluster.id()); |
197 | return points == null || points.isEmpty() || points.contains(connectPoint); | 206 | return points == null || points.isEmpty() || points.contains(connectPoint); |
198 | } | 207 | } |
199 | 208 | ||
200 | /** | 209 | /** |
210 | + * Returns the size of the cluster broadcast set. | ||
211 | + * | ||
212 | + * @param clusterId cluster identifier | ||
213 | + * @return size of the cluster broadcast set | ||
214 | + */ | ||
215 | + int broadcastSetSize(ClusterId clusterId) { | ||
216 | + return broadcastSets.get(clusterId).size(); | ||
217 | + } | ||
218 | + | ||
219 | + /** | ||
201 | * Returns the set of pre-computed shortest paths between source and | 220 | * Returns the set of pre-computed shortest paths between source and |
202 | * destination devices. | 221 | * destination devices. |
203 | * | 222 | * | ... | ... |
... | @@ -144,7 +144,7 @@ class SimpleTopologyStore { | ... | @@ -144,7 +144,7 @@ class SimpleTopologyStore { |
144 | * @return true if broadcast allowed; false otherwise | 144 | * @return true if broadcast allowed; false otherwise |
145 | */ | 145 | */ |
146 | boolean isBroadcastPoint(DefaultTopology topology, ConnectPoint connectPoint) { | 146 | boolean isBroadcastPoint(DefaultTopology topology, ConnectPoint connectPoint) { |
147 | - return topology.isInBroadcastTree(connectPoint); | 147 | + return topology.isBroadcastPoint(connectPoint); |
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** | ... | ... |
core/trivial/src/test/java/org/onlab/onos/net/trivial/topology/impl/DefaultTopologyTest.java
0 → 100644
1 | +package org.onlab.onos.net.trivial.topology.impl; | ||
2 | + | ||
3 | +import org.junit.Before; | ||
4 | +import org.junit.Test; | ||
5 | +import org.onlab.onos.net.ConnectPoint; | ||
6 | +import org.onlab.onos.net.Device; | ||
7 | +import org.onlab.onos.net.DeviceId; | ||
8 | +import org.onlab.onos.net.Link; | ||
9 | +import org.onlab.onos.net.Path; | ||
10 | +import org.onlab.onos.net.PortNumber; | ||
11 | +import org.onlab.onos.net.provider.ProviderId; | ||
12 | +import org.onlab.onos.net.topology.ClusterId; | ||
13 | +import org.onlab.onos.net.topology.GraphDescription; | ||
14 | +import org.onlab.onos.net.topology.LinkWeight; | ||
15 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
16 | +import org.onlab.onos.net.topology.TopologyEdge; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | + | ||
20 | +import static com.google.common.collect.ImmutableSet.of; | ||
21 | +import static org.junit.Assert.*; | ||
22 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
23 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
24 | +import static org.onlab.onos.net.trivial.topology.impl.SimpleTopologyManagerTest.device; | ||
25 | +import static org.onlab.onos.net.trivial.topology.impl.SimpleTopologyManagerTest.link; | ||
26 | + | ||
27 | +/** | ||
28 | + * Test of the default topology implementation. | ||
29 | + */ | ||
30 | +public class DefaultTopologyTest { | ||
31 | + | ||
32 | + public static final ProviderId PID = new ProviderId("foo.bar"); | ||
33 | + | ||
34 | + public static final DeviceId D1 = deviceId("of:1"); | ||
35 | + public static final DeviceId D2 = deviceId("of:2"); | ||
36 | + public static final DeviceId D3 = deviceId("of:3"); | ||
37 | + public static final DeviceId D4 = deviceId("of:4"); | ||
38 | + public static final DeviceId D5 = deviceId("of:5"); | ||
39 | + | ||
40 | + public static final PortNumber P1 = portNumber(1); | ||
41 | + public static final PortNumber P2 = portNumber(2); | ||
42 | + | ||
43 | + public static final LinkWeight WEIGHT = new LinkWeight() { | ||
44 | + @Override | ||
45 | + public double weight(TopologyEdge edge) { | ||
46 | + return edge.src().deviceId().equals(D4) || | ||
47 | + edge.dst().deviceId().equals(D4) ? 2.0 : 1.0; | ||
48 | + } | ||
49 | + }; | ||
50 | + | ||
51 | + private DefaultTopology dt; | ||
52 | + | ||
53 | + @Before | ||
54 | + public void setUp() { | ||
55 | + long now = System.currentTimeMillis(); | ||
56 | + Set<Device> devices = of(device("1"), device("2"), | ||
57 | + device("3"), device("4"), | ||
58 | + device("5")); | ||
59 | + Set<Link> links = of(link("1", 1, "2", 1), link("2", 1, "1", 1), | ||
60 | + link("3", 2, "2", 2), link("2", 2, "3", 2), | ||
61 | + link("1", 3, "4", 3), link("4", 3, "1", 3), | ||
62 | + link("3", 4, "4", 4), link("4", 4, "3", 4)); | ||
63 | + GraphDescription graphDescription = | ||
64 | + new DefaultGraphDescription(now, devices, links); | ||
65 | + | ||
66 | + dt = new DefaultTopology(PID, graphDescription); | ||
67 | + assertEquals("incorrect supplier", PID, dt.providerId()); | ||
68 | + assertEquals("incorrect time", now, dt.time()); | ||
69 | + assertEquals("incorrect device count", 5, dt.deviceCount()); | ||
70 | + assertEquals("incorrect link count", 8, dt.linkCount()); | ||
71 | + assertEquals("incorrect cluster count", 2, dt.clusterCount()); | ||
72 | + assertEquals("incorrect broadcast set size", 6, | ||
73 | + dt.broadcastSetSize(ClusterId.clusterId(0))); | ||
74 | + } | ||
75 | + | ||
76 | + @Test | ||
77 | + public void pathRelated() { | ||
78 | + Set<Path> paths = dt.getPaths(D1, D2); | ||
79 | + assertEquals("incorrect path count", 1, paths.size()); | ||
80 | + | ||
81 | + paths = dt.getPaths(D1, D3); | ||
82 | + assertEquals("incorrect path count", 2, paths.size()); | ||
83 | + | ||
84 | + paths = dt.getPaths(D1, D5); | ||
85 | + assertTrue("no paths expected", paths.isEmpty()); | ||
86 | + | ||
87 | + paths = dt.getPaths(D1, D3, WEIGHT); | ||
88 | + assertEquals("incorrect path count", 1, paths.size()); | ||
89 | + } | ||
90 | + | ||
91 | + @Test | ||
92 | + public void pointRelated() { | ||
93 | + assertTrue("should be infrastructure point", | ||
94 | + dt.isInfrastructure(new ConnectPoint(D1, P1))); | ||
95 | + assertFalse("should not be infrastructure point", | ||
96 | + dt.isInfrastructure(new ConnectPoint(D1, P2))); | ||
97 | + } | ||
98 | + | ||
99 | + @Test | ||
100 | + public void clusterRelated() { | ||
101 | + Set<TopologyCluster> clusters = dt.getClusters(); | ||
102 | + assertEquals("incorrect cluster count", 2, clusters.size()); | ||
103 | + | ||
104 | + TopologyCluster c = dt.getCluster(D1); | ||
105 | + Set<DeviceId> devs = dt.getClusterDevices(c); | ||
106 | + assertEquals("incorrect cluster device count", 4, devs.size()); | ||
107 | + assertTrue("cluster should contain D2", devs.contains(D2)); | ||
108 | + assertFalse("cluster should not contain D5", devs.contains(D5)); | ||
109 | + } | ||
110 | + | ||
111 | +} |
... | @@ -101,7 +101,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -101,7 +101,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
101 | for (int i = 0; i < flowRules.length; i++) { | 101 | for (int i = 0; i < flowRules.length; i++) { |
102 | applyRule(flowRules[i]); | 102 | applyRule(flowRules[i]); |
103 | } | 103 | } |
104 | - | ||
105 | } | 104 | } |
106 | 105 | ||
107 | private void applyRule(FlowRule flowRule) { | 106 | private void applyRule(FlowRule flowRule) { |
... | @@ -120,9 +119,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -120,9 +119,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
120 | .setHardTimeout(10) | 119 | .setHardTimeout(10) |
121 | .setPriority(flowRule.priority()) | 120 | .setPriority(flowRule.priority()) |
122 | .build(); | 121 | .build(); |
123 | - | ||
124 | sw.sendMsg(fm); | 122 | sw.sendMsg(fm); |
125 | - | ||
126 | } | 123 | } |
127 | 124 | ||
128 | private List<OFAction> buildActions(List<Instruction> instructions, OFFactory factory) { | 125 | private List<OFAction> buildActions(List<Instruction> instructions, OFFactory factory) { | ... | ... |
-
Please register or login to post a comment