alshabib

link discovery no longer need a parsed packet

...@@ -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,11 +41,9 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -41,11 +41,9 @@ 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<>();
46 45
47 - protected List<PacketListener> ofPacketListener = 46 + protected List<PacketListener> ofPacketListener = new ArrayList<>();
48 - new ArrayList<>();
49 47
50 private final Controller ctrl = new Controller(); 48 private final Controller ctrl = new Controller();
51 49
...@@ -126,7 +124,6 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -126,7 +124,6 @@ public class OpenFlowControllerImpl implements OpenFlowController {
126 break; 124 break;
127 case PACKET_IN: 125 case PACKET_IN:
128 for (PacketListener p : ofPacketListener) { 126 for (PacketListener p : ofPacketListener) {
129 - //TODO fix me!
130 p.handlePacket(DefaultPacketContext 127 p.handlePacket(DefaultPacketContext
131 .packetContextFromPacketIn(this.getSwitch(dpid), 128 .packetContextFromPacketIn(this.getSwitch(dpid),
132 (OFPacketIn) msg)); 129 (OFPacketIn) msg));
......
...@@ -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 /**
......