Showing
6 changed files
with
273 additions
and
265 deletions
... | @@ -80,4 +80,9 @@ public final class DefaultPacketContext implements PacketContext { | ... | @@ -80,4 +80,9 @@ public final class DefaultPacketContext implements PacketContext { |
80 | return pktin.getInPort().getPortNumber(); | 80 | return pktin.getInPort().getPortNumber(); |
81 | } | 81 | } |
82 | 82 | ||
83 | + @Override | ||
84 | + public byte[] unparsed() { | ||
85 | + return pktin.getData().clone(); | ||
86 | + } | ||
87 | + | ||
83 | } | 88 | } | ... | ... |
... | @@ -44,6 +44,12 @@ public interface PacketContext { | ... | @@ -44,6 +44,12 @@ public interface PacketContext { |
44 | public Ethernet parsed(); | 44 | public Ethernet parsed(); |
45 | 45 | ||
46 | /** | 46 | /** |
47 | + * Provide an unparsed copy of the data. | ||
48 | + * @return the unparsed form of the payload. | ||
49 | + */ | ||
50 | + public byte[] unparsed(); | ||
51 | + | ||
52 | + /** | ||
47 | * Provide the dpid of the switch where the packet in arrived. | 53 | * Provide the dpid of the switch where the packet in arrived. |
48 | * @return the dpid of the switch. | 54 | * @return the dpid of the switch. |
49 | */ | 55 | */ | ... | ... |
... | @@ -41,247 +41,244 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -41,247 +41,244 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
41 | new ConcurrentHashMap<Dpid, OpenFlowSwitch>(); | 41 | new ConcurrentHashMap<Dpid, OpenFlowSwitch>(); |
42 | 42 | ||
43 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); | 43 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); |
44 | - protected Set<OpenFlowSwitchListener> ofEventListener = | 44 | + protected Set<OpenFlowSwitchListener> ofEventListener = new HashSet<>(); |
45 | - new HashSet<>(); | 45 | + |
46 | - | 46 | + protected List<PacketListener> ofPacketListener = new ArrayList<>(); |
47 | - protected List<PacketListener> ofPacketListener = | 47 | + |
48 | - new ArrayList<>(); | 48 | + private final Controller ctrl = new Controller(); |
49 | - | 49 | + |
50 | - private final Controller ctrl = new Controller(); | 50 | + @Activate |
51 | - | 51 | + public void activate() { |
52 | - @Activate | 52 | + ctrl.start(agent); |
53 | - public void activate() { | 53 | + } |
54 | - ctrl.start(agent); | 54 | + |
55 | - } | 55 | + @Deactivate |
56 | - | 56 | + public void deactivate() { |
57 | - @Deactivate | 57 | + ctrl.stop(); |
58 | - public void deactivate() { | 58 | + } |
59 | - ctrl.stop(); | 59 | + |
60 | - } | 60 | + @Override |
61 | - | 61 | + public Iterable<OpenFlowSwitch> getSwitches() { |
62 | - @Override | 62 | + return connectedSwitches.values(); |
63 | - public Iterable<OpenFlowSwitch> getSwitches() { | 63 | + } |
64 | - return connectedSwitches.values(); | 64 | + |
65 | - } | 65 | + @Override |
66 | - | 66 | + public Iterable<OpenFlowSwitch> getMasterSwitches() { |
67 | - @Override | 67 | + return activeMasterSwitches.values(); |
68 | - public Iterable<OpenFlowSwitch> getMasterSwitches() { | 68 | + } |
69 | - return activeMasterSwitches.values(); | 69 | + |
70 | - } | 70 | + @Override |
71 | - | 71 | + public Iterable<OpenFlowSwitch> getEqualSwitches() { |
72 | - @Override | 72 | + return activeEqualSwitches.values(); |
73 | - public Iterable<OpenFlowSwitch> getEqualSwitches() { | 73 | + } |
74 | - return activeEqualSwitches.values(); | 74 | + |
75 | - } | 75 | + @Override |
76 | - | 76 | + public OpenFlowSwitch getSwitch(Dpid dpid) { |
77 | - @Override | 77 | + return connectedSwitches.get(dpid); |
78 | - public OpenFlowSwitch getSwitch(Dpid dpid) { | 78 | + } |
79 | - return connectedSwitches.get(dpid); | 79 | + |
80 | - } | 80 | + @Override |
81 | - | 81 | + public OpenFlowSwitch getMasterSwitch(Dpid dpid) { |
82 | - @Override | 82 | + return activeMasterSwitches.get(dpid); |
83 | - public OpenFlowSwitch getMasterSwitch(Dpid dpid) { | 83 | + } |
84 | - return activeMasterSwitches.get(dpid); | 84 | + |
85 | - } | 85 | + @Override |
86 | - | 86 | + public OpenFlowSwitch getEqualSwitch(Dpid dpid) { |
87 | - @Override | 87 | + return activeEqualSwitches.get(dpid); |
88 | - public OpenFlowSwitch getEqualSwitch(Dpid dpid) { | 88 | + } |
89 | - return activeEqualSwitches.get(dpid); | 89 | + |
90 | - } | 90 | + @Override |
91 | - | 91 | + public void addListener(OpenFlowSwitchListener listener) { |
92 | - @Override | 92 | + if (!ofEventListener.contains(listener)) { |
93 | - public void addListener(OpenFlowSwitchListener listener) { | 93 | + this.ofEventListener.add(listener); |
94 | - if (!ofEventListener.contains(listener)) { | 94 | + } |
95 | - this.ofEventListener.add(listener); | 95 | + } |
96 | - } | 96 | + |
97 | - } | 97 | + @Override |
98 | - | 98 | + public void removeListener(OpenFlowSwitchListener listener) { |
99 | - @Override | 99 | + this.ofEventListener.remove(listener); |
100 | - public void removeListener(OpenFlowSwitchListener listener) { | 100 | + } |
101 | - this.ofEventListener.remove(listener); | 101 | + |
102 | - } | 102 | + @Override |
103 | - | 103 | + public void addPacketListener(int priority, PacketListener listener) { |
104 | - @Override | 104 | + ofPacketListener.add(priority, listener); |
105 | - public void addPacketListener(int priority, PacketListener listener) { | 105 | + } |
106 | - ofPacketListener.add(priority, listener); | 106 | + |
107 | - } | 107 | + @Override |
108 | - | 108 | + public void removePacketListener(PacketListener listener) { |
109 | - @Override | 109 | + ofPacketListener.remove(listener); |
110 | - public void removePacketListener(PacketListener listener) { | 110 | + } |
111 | - ofPacketListener.remove(listener); | 111 | + |
112 | - } | 112 | + @Override |
113 | - | 113 | + public void write(Dpid dpid, OFMessage msg) { |
114 | - @Override | 114 | + this.getSwitch(dpid).sendMsg(msg); |
115 | - public void write(Dpid dpid, OFMessage msg) { | 115 | + } |
116 | - this.getSwitch(dpid).sendMsg(msg); | 116 | + |
117 | - } | 117 | + @Override |
118 | - | 118 | + public void processPacket(Dpid dpid, OFMessage msg) { |
119 | - @Override | 119 | + switch (msg.getType()) { |
120 | - public void processPacket(Dpid dpid, OFMessage msg) { | 120 | + case PORT_STATUS: |
121 | - switch (msg.getType()) { | 121 | + for (OpenFlowSwitchListener l : ofEventListener) { |
122 | - case PORT_STATUS: | 122 | + l.portChanged(dpid, (OFPortStatus) msg); |
123 | - for (OpenFlowSwitchListener l : ofEventListener) { | 123 | + } |
124 | - l.portChanged(dpid, (OFPortStatus) msg); | 124 | + break; |
125 | - } | 125 | + case PACKET_IN: |
126 | - break; | 126 | + for (PacketListener p : ofPacketListener) { |
127 | - case PACKET_IN: | 127 | + p.handlePacket(DefaultPacketContext |
128 | - for (PacketListener p : ofPacketListener) { | 128 | + .packetContextFromPacketIn(this.getSwitch(dpid), |
129 | - //TODO fix me! | 129 | + (OFPacketIn) msg)); |
130 | - p.handlePacket(DefaultPacketContext | 130 | + } |
131 | - .packetContextFromPacketIn(this.getSwitch(dpid), | 131 | + break; |
132 | - (OFPacketIn) msg)); | 132 | + default: |
133 | - } | 133 | + log.warn("Handling message type {} not yet implemented {}", |
134 | - break; | 134 | + msg.getType(), msg); |
135 | - default: | 135 | + } |
136 | - log.warn("Handling message type {} not yet implemented {}", | 136 | + } |
137 | - msg.getType(), msg); | 137 | + |
138 | - } | 138 | + @Override |
139 | - } | 139 | + public void setRole(Dpid dpid, RoleState role) { |
140 | - | 140 | + getSwitch(dpid).setRole(role); |
141 | - @Override | 141 | + } |
142 | - public void setRole(Dpid dpid, RoleState role) { | 142 | + |
143 | - getSwitch(dpid).setRole(role); | 143 | + /** |
144 | - } | 144 | + * Implementation of an OpenFlow Agent which is responsible for |
145 | - | 145 | + * keeping track of connected switches and the state in which |
146 | - /** | 146 | + * they are. |
147 | - * Implementation of an OpenFlow Agent which is responsible for | 147 | + */ |
148 | - * keeping track of connected switches and the state in which | 148 | + public class OpenFlowSwitchAgent implements OpenFlowAgent { |
149 | - * they are. | 149 | + |
150 | - */ | 150 | + private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class); |
151 | - public class OpenFlowSwitchAgent implements OpenFlowAgent { | 151 | + private final Lock switchLock = new ReentrantLock(); |
152 | - | 152 | + |
153 | - private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class); | 153 | + @Override |
154 | - private final Lock switchLock = new ReentrantLock(); | 154 | + public boolean addConnectedSwitch(Dpid dpid, OpenFlowSwitch sw) { |
155 | - | 155 | + if (connectedSwitches.get(dpid) != null) { |
156 | - @Override | 156 | + log.error("Trying to add connectedSwitch but found a previous " |
157 | - public boolean addConnectedSwitch(Dpid dpid, OpenFlowSwitch sw) { | 157 | + + "value for dpid: {}", dpid); |
158 | - if (connectedSwitches.get(dpid) != null) { | 158 | + return false; |
159 | - log.error("Trying to add connectedSwitch but found a previous " | 159 | + } else { |
160 | - + "value for dpid: {}", dpid); | 160 | + log.error("Added switch {}", dpid); |
161 | - return false; | 161 | + connectedSwitches.put(dpid, sw); |
162 | - } else { | 162 | + for (OpenFlowSwitchListener l : ofEventListener) { |
163 | - log.error("Added switch {}", dpid); | 163 | + l.switchAdded(dpid); |
164 | - connectedSwitches.put(dpid, sw); | 164 | + } |
165 | - for (OpenFlowSwitchListener l : ofEventListener) { | 165 | + return true; |
166 | - l.switchAdded(dpid); | 166 | + } |
167 | - } | 167 | + } |
168 | - return true; | 168 | + |
169 | - } | 169 | + @Override |
170 | - } | 170 | + public boolean validActivation(Dpid dpid) { |
171 | - | 171 | + if (connectedSwitches.get(dpid) == null) { |
172 | - @Override | 172 | + log.error("Trying to activate switch but is not in " |
173 | - public boolean validActivation(Dpid dpid) { | 173 | + + "connected switches: dpid {}. Aborting ..", |
174 | - if (connectedSwitches.get(dpid) == null) { | 174 | + dpid); |
175 | - log.error("Trying to activate switch but is not in " | 175 | + return false; |
176 | - + "connected switches: dpid {}. Aborting ..", | 176 | + } |
177 | - dpid); | 177 | + if (activeMasterSwitches.get(dpid) != null || |
178 | - return false; | 178 | + activeEqualSwitches.get(dpid) != null) { |
179 | - } | 179 | + log.error("Trying to activate switch but it is already " |
180 | - if (activeMasterSwitches.get(dpid) != null || | 180 | + + "activated: dpid {}. Found in activeMaster: {} " |
181 | - activeEqualSwitches.get(dpid) != null) { | 181 | + + "Found in activeEqual: {}. Aborting ..", new Object[]{ |
182 | - log.error("Trying to activate switch but it is already " | 182 | + dpid, |
183 | - + "activated: dpid {}. Found in activeMaster: {} " | 183 | + (activeMasterSwitches.get(dpid) == null) ? 'N' : 'Y', |
184 | - + "Found in activeEqual: {}. Aborting ..", new Object[]{ | 184 | + (activeEqualSwitches.get(dpid) == null) ? 'N' : 'Y'}); |
185 | - dpid, | 185 | + return false; |
186 | - (activeMasterSwitches.get(dpid) == null) ? 'N' : 'Y', | 186 | + } |
187 | - (activeEqualSwitches.get(dpid) == null) ? 'N' : 'Y'}); | 187 | + return true; |
188 | - return false; | 188 | + } |
189 | - } | 189 | + |
190 | - return true; | 190 | + |
191 | - } | 191 | + @Override |
192 | - | 192 | + public boolean addActivatedMasterSwitch(Dpid dpid, OpenFlowSwitch sw) { |
193 | - | 193 | + switchLock.lock(); |
194 | - @Override | 194 | + try { |
195 | - public boolean addActivatedMasterSwitch(Dpid dpid, OpenFlowSwitch sw) { | 195 | + if (!validActivation(dpid)) { |
196 | - switchLock.lock(); | 196 | + return false; |
197 | - try { | 197 | + } |
198 | - if (!validActivation(dpid)) { | 198 | + activeMasterSwitches.put(dpid, sw); |
199 | - return false; | 199 | + return true; |
200 | - } | 200 | + } finally { |
201 | - activeMasterSwitches.put(dpid, sw); | 201 | + switchLock.unlock(); |
202 | - return true; | 202 | + } |
203 | - } finally { | 203 | + } |
204 | - switchLock.unlock(); | 204 | + |
205 | - } | 205 | + @Override |
206 | - } | 206 | + public boolean addActivatedEqualSwitch(Dpid dpid, OpenFlowSwitch sw) { |
207 | - | 207 | + switchLock.lock(); |
208 | - @Override | 208 | + try { |
209 | - public boolean addActivatedEqualSwitch(Dpid dpid, OpenFlowSwitch sw) { | 209 | + if (!validActivation(dpid)) { |
210 | - switchLock.lock(); | 210 | + return false; |
211 | - try { | 211 | + } |
212 | - if (!validActivation(dpid)) { | 212 | + activeEqualSwitches.put(dpid, sw); |
213 | - return false; | 213 | + log.info("Added Activated EQUAL Switch {}", dpid); |
214 | - } | 214 | + return true; |
215 | - activeEqualSwitches.put(dpid, sw); | 215 | + } finally { |
216 | - log.info("Added Activated EQUAL Switch {}", dpid); | 216 | + switchLock.unlock(); |
217 | - return true; | 217 | + } |
218 | - } finally { | 218 | + } |
219 | - switchLock.unlock(); | 219 | + |
220 | - } | 220 | + @Override |
221 | - } | 221 | + public void transitionToMasterSwitch(Dpid dpid) { |
222 | - | 222 | + switchLock.lock(); |
223 | - @Override | 223 | + try { |
224 | - public void transitionToMasterSwitch(Dpid dpid) { | 224 | + if (activeMasterSwitches.containsKey(dpid)) { |
225 | - switchLock.lock(); | 225 | + return; |
226 | - try { | 226 | + } |
227 | - if (activeMasterSwitches.containsKey(dpid)) { | 227 | + OpenFlowSwitch sw = activeEqualSwitches.remove(dpid); |
228 | - return; | 228 | + if (sw == null) { |
229 | - } | 229 | + sw = getSwitch(dpid); |
230 | - OpenFlowSwitch sw = activeEqualSwitches.remove(dpid); | 230 | + if (sw == null) { |
231 | - if (sw == null) { | 231 | + log.error("Transition to master called on sw {}, but switch " |
232 | - sw = getSwitch(dpid); | 232 | + + "was not found in controller-cache", dpid); |
233 | - if (sw == null) { | 233 | + return; |
234 | - log.error("Transition to master called on sw {}, but switch " | ||
235 | - + "was not found in controller-cache", dpid); | ||
236 | - return; | ||
237 | - } | ||
238 | - } | ||
239 | - log.info("Transitioned switch {} to MASTER", dpid); | ||
240 | - activeMasterSwitches.put(dpid, sw); | ||
241 | - } finally { | ||
242 | - switchLock.unlock(); | ||
243 | - } | ||
244 | - } | ||
245 | - | ||
246 | - | ||
247 | - @Override | ||
248 | - public void transitionToEqualSwitch(Dpid dpid) { | ||
249 | - switchLock.lock(); | ||
250 | - try { | ||
251 | - if (activeEqualSwitches.containsKey(dpid)) { | ||
252 | - return; | ||
253 | - } | ||
254 | - OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); | ||
255 | - if (sw == null) { | ||
256 | - log.error("Transition to equal called on sw {}, but switch " | ||
257 | - + "was not found in controller-cache", dpid); | ||
258 | - return; | ||
259 | - } | ||
260 | - log.info("Transitioned switch {} to EQUAL", dpid); | ||
261 | - activeEqualSwitches.put(dpid, sw); | ||
262 | - } finally { | ||
263 | - switchLock.unlock(); | ||
264 | - } | ||
265 | - | ||
266 | - } | ||
267 | - | ||
268 | - @Override | ||
269 | - public void removeConnectedSwitch(Dpid dpid) { | ||
270 | - connectedSwitches.remove(dpid); | ||
271 | - OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); | ||
272 | - if (sw == null) { | ||
273 | - sw = activeEqualSwitches.remove(dpid); | ||
274 | - } | ||
275 | - for (OpenFlowSwitchListener l : ofEventListener) { | ||
276 | - l.switchRemoved(dpid); | ||
277 | - } | ||
278 | - } | ||
279 | - | ||
280 | - @Override | ||
281 | - public void processMessage(Dpid dpid, OFMessage m) { | ||
282 | - processPacket(dpid, m); | ||
283 | - } | ||
284 | } | 234 | } |
235 | + } | ||
236 | + log.info("Transitioned switch {} to MASTER", dpid); | ||
237 | + activeMasterSwitches.put(dpid, sw); | ||
238 | + } finally { | ||
239 | + switchLock.unlock(); | ||
240 | + } | ||
241 | + } | ||
242 | + | ||
243 | + | ||
244 | + @Override | ||
245 | + public void transitionToEqualSwitch(Dpid dpid) { | ||
246 | + switchLock.lock(); | ||
247 | + try { | ||
248 | + if (activeEqualSwitches.containsKey(dpid)) { | ||
249 | + return; | ||
250 | + } | ||
251 | + OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); | ||
252 | + if (sw == null) { | ||
253 | + log.error("Transition to equal called on sw {}, but switch " | ||
254 | + + "was not found in controller-cache", dpid); | ||
255 | + return; | ||
256 | + } | ||
257 | + log.info("Transitioned switch {} to EQUAL", dpid); | ||
258 | + activeEqualSwitches.put(dpid, sw); | ||
259 | + } finally { | ||
260 | + switchLock.unlock(); | ||
261 | + } | ||
262 | + | ||
263 | + } | ||
264 | + | ||
265 | + @Override | ||
266 | + public void removeConnectedSwitch(Dpid dpid) { | ||
267 | + connectedSwitches.remove(dpid); | ||
268 | + OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); | ||
269 | + if (sw == null) { | ||
270 | + sw = activeEqualSwitches.remove(dpid); | ||
271 | + } | ||
272 | + for (OpenFlowSwitchListener l : ofEventListener) { | ||
273 | + l.switchRemoved(dpid); | ||
274 | + } | ||
275 | + } | ||
276 | + | ||
277 | + @Override | ||
278 | + public void processMessage(Dpid dpid, OFMessage m) { | ||
279 | + processPacket(dpid, m); | ||
280 | + } | ||
281 | + } | ||
285 | 282 | ||
286 | 283 | ||
287 | } | 284 | } | ... | ... |
... | @@ -21,9 +21,9 @@ import java.util.Collections; | ... | @@ -21,9 +21,9 @@ import java.util.Collections; |
21 | import java.util.HashMap; | 21 | import java.util.HashMap; |
22 | import java.util.HashSet; | 22 | import java.util.HashSet; |
23 | import java.util.Iterator; | 23 | import java.util.Iterator; |
24 | -import java.util.List; | ||
25 | import java.util.Map; | 24 | import java.util.Map; |
26 | import java.util.Set; | 25 | import java.util.Set; |
26 | +import java.util.concurrent.ConcurrentHashMap; | ||
27 | import java.util.concurrent.TimeUnit; | 27 | import java.util.concurrent.TimeUnit; |
28 | import java.util.concurrent.atomic.AtomicInteger; | 28 | import java.util.concurrent.atomic.AtomicInteger; |
29 | 29 | ||
... | @@ -85,6 +85,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -85,6 +85,7 @@ public class LinkDiscovery implements TimerTask { |
85 | private final boolean useBDDP; | 85 | private final boolean useBDDP; |
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 | 89 | ||
89 | /** | 90 | /** |
90 | * Instantiates discovery manager for the given physical switch. Creates a | 91 | * Instantiates discovery manager for the given physical switch. Creates a |
... | @@ -103,6 +104,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -103,6 +104,7 @@ public class LinkDiscovery implements TimerTask { |
103 | this.linkProvider = providerService; | 104 | this.linkProvider = providerService; |
104 | this.slowPorts = Collections.synchronizedSet(new HashSet<Integer>()); | 105 | this.slowPorts = Collections.synchronizedSet(new HashSet<Integer>()); |
105 | this.fastPorts = Collections.synchronizedSet(new HashSet<Integer>()); | 106 | this.fastPorts = Collections.synchronizedSet(new HashSet<Integer>()); |
107 | + this.ports = new ConcurrentHashMap<>(); | ||
106 | this.portProbeCount = new HashMap<Integer, AtomicInteger>(); | 108 | this.portProbeCount = new HashMap<Integer, AtomicInteger>(); |
107 | this.lldpPacket = new ONLabLddp(); | 109 | this.lldpPacket = new ONLabLddp(); |
108 | this.lldpPacket.setSwitch(this.sw.getId()); | 110 | this.lldpPacket.setSwitch(this.sw.getId()); |
... | @@ -140,7 +142,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -140,7 +142,7 @@ public class LinkDiscovery implements TimerTask { |
140 | */ | 142 | */ |
141 | public void addPort(final OFPortDesc port) { | 143 | public void addPort(final OFPortDesc port) { |
142 | // Ignore ports that are not on this switch, or already booted. */ | 144 | // Ignore ports that are not on this switch, or already booted. */ |
143 | - | 145 | + this.ports.put(port.getPortNo().getPortNumber(), port); |
144 | synchronized (this) { | 146 | synchronized (this) { |
145 | this.log.debug("sending init probe to port {}", | 147 | this.log.debug("sending init probe to port {}", |
146 | port.getPortNo().getPortNumber()); | 148 | port.getPortNo().getPortNumber()); |
... | @@ -274,12 +276,10 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -274,12 +276,10 @@ public class LinkDiscovery implements TimerTask { |
274 | * Handles an incoming LLDP packet. Creates link in topology and sends ACK | 276 | * Handles an incoming LLDP packet. Creates link in topology and sends ACK |
275 | * to port where LLDP originated. | 277 | * to port where LLDP originated. |
276 | */ | 278 | */ |
277 | - @SuppressWarnings("rawtypes") | 279 | + public void handleLLDP(final byte[] pkt, Integer inPort) { |
278 | - public void handleLLDP(final Ethernet eth, Integer inPort) { | ||
279 | - | ||
280 | - final byte[] pkt = eth.serialize(); | ||
281 | 280 | ||
282 | - if (ONLabLddp.isOVXLLDP(pkt)) { | 281 | + short ethType = ONLabLddp.isOVXLLDP(pkt); |
282 | + if (ethType == Ethernet.TYPE_LLDP || ethType == Ethernet.TYPE_BSN) { | ||
283 | final Integer dstPort = inPort; | 283 | final Integer dstPort = inPort; |
284 | final DPIDandPort dp = ONLabLddp.parseLLDP(pkt); | 284 | final DPIDandPort dp = ONLabLddp.parseLLDP(pkt); |
285 | final OpenFlowSwitch srcSwitch = ctrl.getSwitch(new Dpid(dp.getDpid())); | 285 | final OpenFlowSwitch srcSwitch = ctrl.getSwitch(new Dpid(dp.getDpid())); |
... | @@ -296,7 +296,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -296,7 +296,7 @@ public class LinkDiscovery implements TimerTask { |
296 | DeviceId.deviceId("of:" + Long.toHexString(sw.getId())), | 296 | DeviceId.deviceId("of:" + Long.toHexString(sw.getId())), |
297 | PortNumber.portNumber(dstPort)); | 297 | PortNumber.portNumber(dstPort)); |
298 | LinkDescription ld; | 298 | LinkDescription ld; |
299 | - if (eth.getEtherType() == Ethernet.TYPE_BSN) { | 299 | + if (ethType == Ethernet.TYPE_BSN) { |
300 | ld = new DefaultLinkDescription(src, dst, Type.INDIRECT); | 300 | ld = new DefaultLinkDescription(src, dst, Type.INDIRECT); |
301 | } else { | 301 | } else { |
302 | ld = new DefaultLinkDescription(src, dst, Type.DIRECT); | 302 | ld = new DefaultLinkDescription(src, dst, Type.DIRECT); |
... | @@ -307,13 +307,8 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -307,13 +307,8 @@ public class LinkDiscovery implements TimerTask { |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | - private OFPortDesc findPort(List<OFPortDesc> ports, Integer inPort) { | 310 | + private OFPortDesc findPort(Integer inPort) { |
311 | - for (OFPortDesc p : ports) { | 311 | + return ports.get(inPort); |
312 | - if (p.getPortNo().getPortNumber() == inPort) { | ||
313 | - return p; | ||
314 | - } | ||
315 | - } | ||
316 | - return null; | ||
317 | } | 312 | } |
318 | 313 | ||
319 | /** | 314 | /** |
... | @@ -333,7 +328,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -333,7 +328,7 @@ public class LinkDiscovery implements TimerTask { |
333 | final Integer portNumber = fastIterator.next(); | 328 | final Integer portNumber = fastIterator.next(); |
334 | final int probeCount = this.portProbeCount.get(portNumber) | 329 | final int probeCount = this.portProbeCount.get(portNumber) |
335 | .getAndIncrement(); | 330 | .getAndIncrement(); |
336 | - OFPortDesc port = findPort(this.sw.getPorts(), portNumber); | 331 | + OFPortDesc port = findPort(portNumber); |
337 | if (probeCount < LinkDiscovery.MAX_PROBE_COUNT) { | 332 | if (probeCount < LinkDiscovery.MAX_PROBE_COUNT) { |
338 | this.log.debug("sending fast probe to port"); | 333 | this.log.debug("sending fast probe to port"); |
339 | 334 | ||
... | @@ -368,7 +363,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -368,7 +363,7 @@ public class LinkDiscovery implements TimerTask { |
368 | if (this.slowIterator.hasNext()) { | 363 | if (this.slowIterator.hasNext()) { |
369 | final int portNumber = this.slowIterator.next(); | 364 | final int portNumber = this.slowIterator.next(); |
370 | this.log.debug("sending slow probe to port {}", portNumber); | 365 | this.log.debug("sending slow probe to port {}", portNumber); |
371 | - OFPortDesc port = findPort(this.sw.getPorts(), portNumber); | 366 | + OFPortDesc port = findPort(portNumber); |
372 | 367 | ||
373 | OFPacketOut pkt = this.createLLDPPacketOut(port); | 368 | OFPacketOut pkt = this.createLLDPPacketOut(port); |
374 | this.sendMsg(pkt); | 369 | this.sendMsg(pkt); | ... | ... |
... | @@ -87,7 +87,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid | ... | @@ -87,7 +87,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid |
87 | if (ld == null) { | 87 | if (ld == null) { |
88 | return; | 88 | return; |
89 | } | 89 | } |
90 | - ld.handleLLDP(pktCtx.parsed(), | 90 | + ld.handleLLDP(pktCtx.unparsed(), |
91 | pktCtx.inPort()); | 91 | pktCtx.inPort()); |
92 | 92 | ||
93 | } | 93 | } | ... | ... |
... | @@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory; |
30 | * Refer to IEEE Std 802.1ABTM-2009 for more information. | 30 | * Refer to IEEE Std 802.1ABTM-2009 for more information. |
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | -@SuppressWarnings("rawtypes") | ||
34 | public class ONLabLddp extends LLDP { | 33 | public class ONLabLddp extends LLDP { |
35 | 34 | ||
36 | private static final Logger log = LoggerFactory.getLogger(ONLabLddp.class); | 35 | private static final Logger log = LoggerFactory.getLogger(ONLabLddp.class); |
... | @@ -308,28 +307,34 @@ public class ONLabLddp extends LLDP { | ... | @@ -308,28 +307,34 @@ public class ONLabLddp extends LLDP { |
308 | * @param packet | 307 | * @param packet |
309 | * @return | 308 | * @return |
310 | */ | 309 | */ |
311 | - public static boolean isOVXLLDP(byte[] packet) { | 310 | + public static short isOVXLLDP(byte[] packet) { |
312 | if (packet.length < OVX_LLDP_SIZE) { | 311 | if (packet.length < OVX_LLDP_SIZE) { |
313 | - return false; | 312 | + return -1; |
314 | } | 313 | } |
315 | 314 | ||
316 | // Extra offset due to VLAN tag | 315 | // Extra offset due to VLAN tag |
317 | final ByteBuffer bb = ByteBuffer.wrap(packet); | 316 | final ByteBuffer bb = ByteBuffer.wrap(packet); |
318 | int offset = 0; | 317 | int offset = 0; |
319 | - if (bb.getShort(ETHERTYPE_OFFSET) != Ethernet.TYPE_LLDP | 318 | + short ethType = bb.getShort(ETHERTYPE_OFFSET); |
320 | - && bb.getShort(ETHERTYPE_OFFSET) != Ethernet.TYPE_BSN) { | 319 | + if (ethType != Ethernet.TYPE_LLDP |
320 | + && ethType != Ethernet.TYPE_BSN) { | ||
321 | offset = 4; | 321 | offset = 4; |
322 | + ethType = bb.getShort(ETHERTYPE_OFFSET + offset); | ||
323 | + if (ethType != Ethernet.TYPE_LLDP | ||
324 | + && ethType != Ethernet.TYPE_BSN) { | ||
325 | + return -1; | ||
326 | + } | ||
322 | } | 327 | } |
323 | 328 | ||
324 | // Compare packet's organizationally specific TLVs to the expected | 329 | // Compare packet's organizationally specific TLVs to the expected |
325 | // values | 330 | // values |
326 | for (int i = 0; i < OUI_TLV.length; i++) { | 331 | for (int i = 0; i < OUI_TLV.length; i++) { |
327 | if (packet[NAME_TLV_OFFSET + offset + i] != OUI_TLV[i]) { | 332 | if (packet[NAME_TLV_OFFSET + offset + i] != OUI_TLV[i]) { |
328 | - return false; | 333 | + return -1; |
329 | } | 334 | } |
330 | } | 335 | } |
331 | 336 | ||
332 | - return true; | 337 | + return ethType; |
333 | } | 338 | } |
334 | 339 | ||
335 | /** | 340 | /** | ... | ... |
-
Please register or login to post a comment