Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Conflicts: providers/of/link/src/main/java/org/onlab/onos/provider/of/link/impl/OpenFlowLinkProvider.java
Showing
5 changed files
with
131 additions
and
21 deletions
1 | package org.onlab.onos.of.drivers.impl; | 1 | package org.onlab.onos.of.drivers.impl; |
2 | 2 | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.Collections; | ||
3 | import java.util.List; | 5 | import java.util.List; |
4 | import java.util.concurrent.atomic.AtomicBoolean; | 6 | import java.util.concurrent.atomic.AtomicBoolean; |
5 | 7 | ||
... | @@ -11,7 +13,14 @@ import org.onlab.onos.of.controller.driver.SwitchDriverSubHandshakeNotStarted; | ... | @@ -11,7 +13,14 @@ import org.onlab.onos.of.controller.driver.SwitchDriverSubHandshakeNotStarted; |
11 | import org.projectfloodlight.openflow.protocol.OFBarrierRequest; | 13 | import org.projectfloodlight.openflow.protocol.OFBarrierRequest; |
12 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; | 14 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
13 | import org.projectfloodlight.openflow.protocol.OFFactory; | 15 | import org.projectfloodlight.openflow.protocol.OFFactory; |
16 | +import org.projectfloodlight.openflow.protocol.OFMatchV3; | ||
14 | import org.projectfloodlight.openflow.protocol.OFMessage; | 17 | import org.projectfloodlight.openflow.protocol.OFMessage; |
18 | +import org.projectfloodlight.openflow.protocol.OFOxmList; | ||
19 | +import org.projectfloodlight.openflow.protocol.action.OFAction; | ||
20 | +import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; | ||
21 | +import org.projectfloodlight.openflow.types.OFBufferId; | ||
22 | +import org.projectfloodlight.openflow.types.OFPort; | ||
23 | +import org.projectfloodlight.openflow.types.TableId; | ||
15 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
16 | import org.slf4j.LoggerFactory; | 25 | import org.slf4j.LoggerFactory; |
17 | 26 | ||
... | @@ -29,6 +38,9 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { | ... | @@ -29,6 +38,9 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { |
29 | private OFFactory factory; | 38 | private OFFactory factory; |
30 | private long barrierXidToWaitFor = -1; | 39 | private long barrierXidToWaitFor = -1; |
31 | 40 | ||
41 | + private static final short MIN_PRIORITY = 0x0; | ||
42 | + private static final int OFPCML_NO_BUFFER = 0xffff; | ||
43 | + | ||
32 | public OFSwitchImplOVS13(Dpid dpid, OFDescStatsReply desc) { | 44 | public OFSwitchImplOVS13(Dpid dpid, OFDescStatsReply desc) { |
33 | super(dpid); | 45 | super(dpid); |
34 | driverHandshakeComplete = new AtomicBoolean(false); | 46 | driverHandshakeComplete = new AtomicBoolean(false); |
... | @@ -112,6 +124,7 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { | ... | @@ -112,6 +124,7 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { |
112 | 124 | ||
113 | 125 | ||
114 | private void configureSwitch() { | 126 | private void configureSwitch() { |
127 | + populateTableMissEntry(0, true, false, false, 0); | ||
115 | sendBarrier(true); | 128 | sendBarrier(true); |
116 | } | 129 | } |
117 | 130 | ||
... | @@ -135,7 +148,7 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { | ... | @@ -135,7 +148,7 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { |
135 | 148 | ||
136 | @Override | 149 | @Override |
137 | public void write(OFMessage msg) { | 150 | public void write(OFMessage msg) { |
138 | - channel.write(msg); | 151 | + channel.write(Collections.singletonList(msg)); |
139 | 152 | ||
140 | } | 153 | } |
141 | 154 | ||
... | @@ -143,4 +156,78 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { | ... | @@ -143,4 +156,78 @@ public class OFSwitchImplOVS13 extends AbstractOpenFlowSwitch { |
143 | public void write(List<OFMessage> msgs) { | 156 | public void write(List<OFMessage> msgs) { |
144 | channel.write(msgs); | 157 | channel.write(msgs); |
145 | } | 158 | } |
159 | + | ||
160 | + /** | ||
161 | + * By default if none of the booleans in the call are set, then the | ||
162 | + * table-miss entry is added with no instructions, which means that pipeline | ||
163 | + * execution will stop, and the action set associated with the packet will | ||
164 | + * be executed. | ||
165 | + * | ||
166 | + * @param tableToAdd | ||
167 | + * @param toControllerNow as an APPLY_ACTION instruction | ||
168 | + * @param toControllerWrite as a WRITE_ACITION instruction | ||
169 | + * @param toTable as a GOTO_TABLE instruction | ||
170 | + * @param tableToSend | ||
171 | + */ | ||
172 | + @SuppressWarnings("unchecked") | ||
173 | + private void populateTableMissEntry(int tableToAdd, boolean toControllerNow, | ||
174 | + boolean toControllerWrite, | ||
175 | + boolean toTable, int tableToSend) { | ||
176 | + OFOxmList oxmList = OFOxmList.EMPTY; | ||
177 | + OFMatchV3 match = factory.buildMatchV3() | ||
178 | + .setOxmList(oxmList) | ||
179 | + .build(); | ||
180 | + OFAction outc = factory.actions() | ||
181 | + .buildOutput() | ||
182 | + .setPort(OFPort.CONTROLLER) | ||
183 | + .setMaxLen(OFPCML_NO_BUFFER) | ||
184 | + .build(); | ||
185 | + List<OFInstruction> instructions = new ArrayList<OFInstruction>(); | ||
186 | + if (toControllerNow) { | ||
187 | + // table-miss instruction to send to controller immediately | ||
188 | + OFInstruction instr = factory.instructions() | ||
189 | + .buildApplyActions() | ||
190 | + .setActions(Collections.singletonList(outc)) | ||
191 | + .build(); | ||
192 | + instructions.add(instr); | ||
193 | + } | ||
194 | + | ||
195 | + if (toControllerWrite) { | ||
196 | + // table-miss instruction to write-action to send to controller | ||
197 | + // this will be executed whenever the action-set gets executed | ||
198 | + OFInstruction instr = factory.instructions() | ||
199 | + .buildWriteActions() | ||
200 | + .setActions(Collections.singletonList(outc)) | ||
201 | + .build(); | ||
202 | + instructions.add(instr); | ||
203 | + } | ||
204 | + | ||
205 | + if (toTable) { | ||
206 | + // table-miss instruction to goto-table x | ||
207 | + OFInstruction instr = factory.instructions() | ||
208 | + .gotoTable(TableId.of(tableToSend)); | ||
209 | + instructions.add(instr); | ||
210 | + } | ||
211 | + | ||
212 | + if (!toControllerNow && !toControllerWrite && !toTable) { | ||
213 | + // table-miss has no instruction - at which point action-set will be | ||
214 | + // executed - if there is an action to output/group in the action | ||
215 | + // set | ||
216 | + // the packet will be sent there, otherwise it will be dropped. | ||
217 | + instructions = Collections.EMPTY_LIST; | ||
218 | + } | ||
219 | + | ||
220 | + OFMessage tableMissEntry = factory.buildFlowAdd() | ||
221 | + .setTableId(TableId.of(tableToAdd)) | ||
222 | + .setMatch(match) // match everything | ||
223 | + .setInstructions(instructions) | ||
224 | + .setPriority(MIN_PRIORITY) | ||
225 | + .setBufferId(OFBufferId.NO_BUFFER) | ||
226 | + .setIdleTimeout(0) | ||
227 | + .setHardTimeout(0) | ||
228 | + .setXid(getNextTransactionId()) | ||
229 | + .build(); | ||
230 | + sendMsg(tableMissEntry); | ||
231 | + } | ||
232 | + | ||
146 | } | 233 | } | ... | ... |
providers/of/device/src/main/java/org/onlab/onos/provider/of/device/impl/OpenFlowDeviceProvider.java
... | @@ -14,6 +14,7 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -14,6 +14,7 @@ import org.apache.felix.scr.annotations.Deactivate; |
14 | import org.apache.felix.scr.annotations.Reference; | 14 | import org.apache.felix.scr.annotations.Reference; |
15 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 15 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
16 | import org.onlab.onos.net.Device; | 16 | import org.onlab.onos.net.Device; |
17 | +import org.onlab.onos.net.DeviceId; | ||
17 | import org.onlab.onos.net.MastershipRole; | 18 | import org.onlab.onos.net.MastershipRole; |
18 | import org.onlab.onos.net.PortNumber; | 19 | import org.onlab.onos.net.PortNumber; |
19 | import org.onlab.onos.net.device.DefaultDeviceDescription; | 20 | import org.onlab.onos.net.device.DefaultDeviceDescription; |
... | @@ -66,14 +67,22 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -66,14 +67,22 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
66 | public void activate() { | 67 | public void activate() { |
67 | providerService = providerRegistry.register(this); | 68 | providerService = providerRegistry.register(this); |
68 | controller.addListener(listener); | 69 | controller.addListener(listener); |
70 | + for (OpenFlowSwitch sw : controller.getSwitches()) { | ||
71 | + listener.switchAdded(new Dpid(sw.getId())); | ||
72 | + } | ||
69 | LOG.info("Started"); | 73 | LOG.info("Started"); |
70 | } | 74 | } |
71 | 75 | ||
72 | @Deactivate | 76 | @Deactivate |
73 | public void deactivate() { | 77 | public void deactivate() { |
78 | + for (OpenFlowSwitch sw : controller.getSwitches()) { | ||
79 | + providerService.deviceDisconnected(DeviceId.deviceId("of:" | ||
80 | + + Long.toHexString(sw.getId()))); | ||
81 | + } | ||
74 | providerRegistry.unregister(this); | 82 | providerRegistry.unregister(this); |
75 | controller.removeListener(listener); | 83 | controller.removeListener(listener); |
76 | providerService = null; | 84 | providerService = null; |
85 | + | ||
77 | LOG.info("Stopped"); | 86 | LOG.info("Stopped"); |
78 | } | 87 | } |
79 | 88 | ... | ... |
... | @@ -86,6 +86,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -86,6 +86,7 @@ public class LinkDiscovery implements TimerTask { |
86 | private final OpenFlowController ctrl; | 86 | private final OpenFlowController ctrl; |
87 | private final LinkProviderService linkProvider; | 87 | private final LinkProviderService linkProvider; |
88 | private final Map<Integer, OFPortDesc> ports; | 88 | private final Map<Integer, OFPortDesc> ports; |
89 | + private Timeout timeout; | ||
89 | 90 | ||
90 | /** | 91 | /** |
91 | * Instantiates discovery manager for the given physical switch. Creates a | 92 | * Instantiates discovery manager for the given physical switch. Creates a |
... | @@ -127,7 +128,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -127,7 +128,7 @@ public class LinkDiscovery implements TimerTask { |
127 | addPort(port); | 128 | addPort(port); |
128 | } | 129 | } |
129 | } | 130 | } |
130 | - Timer.getTimer().newTimeout(this, this.probeRate, | 131 | + timeout = Timer.getTimer().newTimeout(this, this.probeRate, |
131 | TimeUnit.MILLISECONDS); | 132 | TimeUnit.MILLISECONDS); |
132 | this.log.debug("Started discovery manager for switch {}", | 133 | this.log.debug("Started discovery manager for switch {}", |
133 | sw.getId()); | 134 | sw.getId()); |
... | @@ -186,6 +187,10 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -186,6 +187,10 @@ public class LinkDiscovery implements TimerTask { |
186 | portnum); | 187 | portnum); |
187 | } | 188 | } |
188 | } | 189 | } |
190 | + ConnectPoint cp = new ConnectPoint( | ||
191 | + DeviceId.deviceId("of:" + Long.toHexString(sw.getId())), | ||
192 | + PortNumber.portNumber(port.getPortNo().getPortNumber())); | ||
193 | + linkProvider.linksVanished(cp); | ||
189 | 194 | ||
190 | } | 195 | } |
191 | 196 | ||
... | @@ -380,14 +385,19 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -380,14 +385,19 @@ public class LinkDiscovery implements TimerTask { |
380 | } | 385 | } |
381 | 386 | ||
382 | // reschedule timer | 387 | // reschedule timer |
383 | - Timer.getTimer().newTimeout(this, this.probeRate, | 388 | + timeout = Timer.getTimer().newTimeout(this, this.probeRate, |
384 | TimeUnit.MILLISECONDS); | 389 | TimeUnit.MILLISECONDS); |
385 | } | 390 | } |
386 | 391 | ||
387 | public void removeAllPorts() { | 392 | public void removeAllPorts() { |
388 | - for (OFPortDesc port : sw.getPorts()) { | 393 | + for (OFPortDesc port : ports.values()) { |
389 | removePort(port); | 394 | removePort(port); |
390 | } | 395 | } |
391 | } | 396 | } |
392 | 397 | ||
398 | + public void stop() { | ||
399 | + removeAllPorts(); | ||
400 | + timeout.cancel(); | ||
401 | + } | ||
402 | + | ||
393 | } | 403 | } | ... | ... |
1 | package org.onlab.onos.provider.of.link.impl; | 1 | package org.onlab.onos.provider.of.link.impl; |
2 | 2 | ||
3 | -import static org.slf4j.LoggerFactory.getLogger; | ||
4 | - | ||
5 | -import java.util.Map; | ||
6 | -import java.util.concurrent.ConcurrentHashMap; | ||
7 | - | ||
8 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
9 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; |
10 | import org.apache.felix.scr.annotations.Deactivate; | 5 | import org.apache.felix.scr.annotations.Deactivate; |
11 | import org.apache.felix.scr.annotations.Reference; | 6 | import org.apache.felix.scr.annotations.Reference; |
12 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 7 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
13 | -import org.onlab.onos.net.ConnectPoint; | ||
14 | import org.onlab.onos.net.DeviceId; | 8 | import org.onlab.onos.net.DeviceId; |
15 | -import org.onlab.onos.net.PortNumber; | ||
16 | import org.onlab.onos.net.link.LinkProvider; | 9 | import org.onlab.onos.net.link.LinkProvider; |
17 | import org.onlab.onos.net.link.LinkProviderRegistry; | 10 | import org.onlab.onos.net.link.LinkProviderRegistry; |
18 | import org.onlab.onos.net.link.LinkProviderService; | 11 | import org.onlab.onos.net.link.LinkProviderService; |
... | @@ -20,16 +13,21 @@ import org.onlab.onos.net.provider.AbstractProvider; | ... | @@ -20,16 +13,21 @@ import org.onlab.onos.net.provider.AbstractProvider; |
20 | import org.onlab.onos.net.provider.ProviderId; | 13 | import org.onlab.onos.net.provider.ProviderId; |
21 | import org.onlab.onos.of.controller.Dpid; | 14 | import org.onlab.onos.of.controller.Dpid; |
22 | import org.onlab.onos.of.controller.OpenFlowController; | 15 | import org.onlab.onos.of.controller.OpenFlowController; |
16 | +import org.onlab.onos.of.controller.OpenFlowSwitch; | ||
23 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; | 17 | import org.onlab.onos.of.controller.OpenFlowSwitchListener; |
24 | import org.onlab.onos.of.controller.PacketContext; | 18 | import org.onlab.onos.of.controller.PacketContext; |
25 | import org.onlab.onos.of.controller.PacketListener; | 19 | import org.onlab.onos.of.controller.PacketListener; |
26 | -import org.onlab.util.Timer; | ||
27 | import org.projectfloodlight.openflow.protocol.OFPortConfig; | 20 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
28 | import org.projectfloodlight.openflow.protocol.OFPortDesc; | 21 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
29 | import org.projectfloodlight.openflow.protocol.OFPortState; | 22 | import org.projectfloodlight.openflow.protocol.OFPortState; |
30 | import org.projectfloodlight.openflow.protocol.OFPortStatus; | 23 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
31 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
32 | 25 | ||
26 | +import java.util.Map; | ||
27 | +import java.util.concurrent.ConcurrentHashMap; | ||
28 | + | ||
29 | +import static org.slf4j.LoggerFactory.getLogger; | ||
30 | + | ||
33 | /** | 31 | /** |
34 | * Provider which uses an OpenFlow controller to detect network | 32 | * Provider which uses an OpenFlow controller to detect network |
35 | * infrastructure links. | 33 | * infrastructure links. |
... | @@ -51,6 +49,8 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid | ... | @@ -51,6 +49,8 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid |
51 | 49 | ||
52 | private final InternalLinkProvider listener = new InternalLinkProvider(); | 50 | private final InternalLinkProvider listener = new InternalLinkProvider(); |
53 | 51 | ||
52 | + private final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>(); | ||
53 | + | ||
54 | /** | 54 | /** |
55 | * Creates an OpenFlow link provider. | 55 | * Creates an OpenFlow link provider. |
56 | */ | 56 | */ |
... | @@ -63,23 +63,28 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid | ... | @@ -63,23 +63,28 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid |
63 | providerService = providerRegistry.register(this); | 63 | providerService = providerRegistry.register(this); |
64 | controller.addListener(listener); | 64 | controller.addListener(listener); |
65 | controller.addPacketListener(0, listener); | 65 | controller.addPacketListener(0, listener); |
66 | + for (OpenFlowSwitch sw : controller.getSwitches()) { | ||
67 | + listener.switchAdded(new Dpid(sw.getId())); | ||
68 | + } | ||
66 | log.info("Started"); | 69 | log.info("Started"); |
67 | } | 70 | } |
68 | 71 | ||
69 | @Deactivate | 72 | @Deactivate |
70 | public void deactivate() { | 73 | public void deactivate() { |
74 | + for (LinkDiscovery ld : discoverers.values()) { | ||
75 | + ld.stop(); | ||
76 | + } | ||
71 | providerRegistry.unregister(this); | 77 | providerRegistry.unregister(this); |
72 | controller.removeListener(listener); | 78 | controller.removeListener(listener); |
73 | controller.removePacketListener(listener); | 79 | controller.removePacketListener(listener); |
74 | providerService = null; | 80 | providerService = null; |
75 | - Timer.getTimer().stop(); | 81 | + |
76 | log.info("Stopped"); | 82 | log.info("Stopped"); |
77 | } | 83 | } |
78 | 84 | ||
79 | 85 | ||
80 | private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener { | 86 | private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener { |
81 | 87 | ||
82 | - private final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>(); | ||
83 | 88 | ||
84 | @Override | 89 | @Override |
85 | public void handlePacket(PacketContext pktCtx) { | 90 | public void handlePacket(PacketContext pktCtx) { |
... | @@ -96,13 +101,13 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid | ... | @@ -96,13 +101,13 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid |
96 | @Override | 101 | @Override |
97 | public void switchAdded(Dpid dpid) { | 102 | public void switchAdded(Dpid dpid) { |
98 | discoverers.put(dpid, new LinkDiscovery(controller.getSwitch(dpid), | 103 | discoverers.put(dpid, new LinkDiscovery(controller.getSwitch(dpid), |
99 | - controller, providerService, useBDDP)); | 104 | + controller, providerService, useBDDP)); |
100 | 105 | ||
101 | } | 106 | } |
102 | 107 | ||
103 | @Override | 108 | @Override |
104 | public void switchRemoved(Dpid dpid) { | 109 | public void switchRemoved(Dpid dpid) { |
105 | - LinkDiscovery ld = this.discoverers.remove(dpid); | 110 | + LinkDiscovery ld = discoverers.remove(dpid); |
106 | if (ld != null) { | 111 | if (ld != null) { |
107 | ld.removeAllPorts(); | 112 | ld.removeAllPorts(); |
108 | } | 113 | } |
... | @@ -122,10 +127,9 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid | ... | @@ -122,10 +127,9 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid |
122 | if (enabled) { | 127 | if (enabled) { |
123 | ld.addPort(port); | 128 | ld.addPort(port); |
124 | } else { | 129 | } else { |
125 | - ConnectPoint cp = new ConnectPoint( | 130 | + /* |
126 | - DeviceId.deviceId("of:" + Long.toHexString(dpid.value())), | 131 | + * remove port calls linkVanished |
127 | - PortNumber.portNumber(port.getPortNo().getPortNumber())); | 132 | + */ |
128 | - providerService.linksVanished(cp); | ||
129 | ld.removePort(port); | 133 | ld.removePort(port); |
130 | } | 134 | } |
131 | 135 | ... | ... |
... | @@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory; |
32 | */ | 32 | */ |
33 | public class ONLabLddp extends LLDP { | 33 | public class ONLabLddp extends LLDP { |
34 | 34 | ||
35 | - private static final Logger log = LoggerFactory.getLogger(ONLabLddp.class); | 35 | + private static final Logger LOG = LoggerFactory.getLogger(ONLabLddp.class); |
36 | // ON.Lab OUI and OVX name for organizationally specific TLVs | 36 | // ON.Lab OUI and OVX name for organizationally specific TLVs |
37 | public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05}; | 37 | public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05}; |
38 | public static final String OVX_NAME = "OpenVirteX"; | 38 | public static final String OVX_NAME = "OpenVirteX"; | ... | ... |
-
Please register or login to post a comment