alshabib

link discovery and providers are implemented

...@@ -2,7 +2,7 @@ package org.onlab.onos.net; ...@@ -2,7 +2,7 @@ package org.onlab.onos.net;
2 2
3 import java.util.Objects; 3 import java.util.Objects;
4 4
5 -import static com.google.common.base.MoreObjects.toStringHelper; 5 +import com.google.common.base.MoreObjects;
6 6
7 /** 7 /**
8 * Abstraction of a network connection point expressed as a pair of the 8 * Abstraction of a network connection point expressed as a pair of the
...@@ -42,7 +42,6 @@ public class ConnectPoint { ...@@ -42,7 +42,6 @@ public class ConnectPoint {
42 * @throws java.lang.IllegalStateException if connection point is not 42 * @throws java.lang.IllegalStateException if connection point is not
43 * associated with a device 43 * associated with a device
44 */ 44 */
45 - @SuppressWarnings("unchecked")
46 public DeviceId deviceId() { 45 public DeviceId deviceId() {
47 if (elementId instanceof DeviceId) { 46 if (elementId instanceof DeviceId) {
48 return (DeviceId) elementId; 47 return (DeviceId) elementId;
...@@ -77,7 +76,7 @@ public class ConnectPoint { ...@@ -77,7 +76,7 @@ public class ConnectPoint {
77 76
78 @Override 77 @Override
79 public String toString() { 78 public String toString() {
80 - return toStringHelper(this) 79 + return MoreObjects.toStringHelper(this)
81 .add("elementId", elementId) 80 .add("elementId", elementId)
82 .add("portNumber", portNumber) 81 .add("portNumber", portNumber)
83 .toString(); 82 .toString();
......
1 package org.onlab.onos.net.trivial.impl; 1 package org.onlab.onos.net.trivial.impl;
2 2
3 -import com.google.common.collect.Sets; 3 +import static com.google.common.base.Preconditions.checkNotNull;
4 +import static org.slf4j.LoggerFactory.getLogger;
5 +
6 +import java.util.Set;
7 +
4 import org.apache.felix.scr.annotations.Activate; 8 import org.apache.felix.scr.annotations.Activate;
5 import org.apache.felix.scr.annotations.Component; 9 import org.apache.felix.scr.annotations.Component;
6 import org.apache.felix.scr.annotations.Deactivate; 10 import org.apache.felix.scr.annotations.Deactivate;
...@@ -24,10 +28,7 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry; ...@@ -24,10 +28,7 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry;
24 import org.onlab.onos.net.provider.AbstractProviderService; 28 import org.onlab.onos.net.provider.AbstractProviderService;
25 import org.slf4j.Logger; 29 import org.slf4j.Logger;
26 30
27 -import java.util.Set; 31 +import com.google.common.collect.Sets;
28 -
29 -import static com.google.common.base.Preconditions.checkNotNull;
30 -import static org.slf4j.LoggerFactory.getLogger;
31 32
32 /** 33 /**
33 * Provides basic implementation of the link SB & NB APIs. 34 * Provides basic implementation of the link SB & NB APIs.
...@@ -35,8 +36,8 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -35,8 +36,8 @@ import static org.slf4j.LoggerFactory.getLogger;
35 @Component(immediate = true) 36 @Component(immediate = true)
36 @Service 37 @Service
37 public class SimpleLinkManager 38 public class SimpleLinkManager
38 - extends AbstractProviderRegistry<LinkProvider, LinkProviderService> 39 +extends AbstractProviderRegistry<LinkProvider, LinkProviderService>
39 - implements LinkService, LinkAdminService, LinkProviderRegistry { 40 +implements LinkService, LinkAdminService, LinkProviderRegistry {
40 41
41 private static final String DEVICE_ID_NULL = "Device ID cannot be null"; 42 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
42 private static final String LINK_DESC_NULL = "Link description cannot be null"; 43 private static final String LINK_DESC_NULL = "Link description cannot be null";
...@@ -156,7 +157,7 @@ public class SimpleLinkManager ...@@ -156,7 +157,7 @@ public class SimpleLinkManager
156 public void linkDetected(LinkDescription linkDescription) { 157 public void linkDetected(LinkDescription linkDescription) {
157 checkNotNull(linkDescription, LINK_DESC_NULL); 158 checkNotNull(linkDescription, LINK_DESC_NULL);
158 checkValidity(); 159 checkValidity();
159 - log.info("Link {} detected", linkDescription); 160 + log.debug("Link {} detected", linkDescription);
160 LinkEvent event = store.createOrUpdateLink(provider().id(), 161 LinkEvent event = store.createOrUpdateLink(provider().id(),
161 linkDescription); 162 linkDescription);
162 post(event); 163 post(event);
......
...@@ -75,4 +75,9 @@ public final class DefaultPacketContext implements PacketContext { ...@@ -75,4 +75,9 @@ public final class DefaultPacketContext implements PacketContext {
75 return new DefaultPacketContext(s, pkt); 75 return new DefaultPacketContext(s, pkt);
76 } 76 }
77 77
78 + @Override
79 + public Integer inPort() {
80 + return pktin.getInPort().getPortNumber();
81 + }
82 +
78 } 83 }
......
...@@ -48,4 +48,10 @@ public interface PacketContext { ...@@ -48,4 +48,10 @@ public interface PacketContext {
48 * @return the dpid of the switch. 48 * @return the dpid of the switch.
49 */ 49 */
50 public Dpid dpid(); 50 public Dpid dpid();
51 +
52 + /**
53 + * Provide the port on which the packet arrived.
54 + * @return the port
55 + */
56 + public Integer inPort();
51 } 57 }
......
...@@ -415,12 +415,14 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { ...@@ -415,12 +415,14 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
415 OFDescStatsReply drep = (OFDescStatsReply) m; 415 OFDescStatsReply drep = (OFDescStatsReply) m;
416 // Here is where we differentiate between different kinds of switches 416 // Here is where we differentiate between different kinds of switches
417 h.sw = h.controller.getOFSwitchInstance(h.thisdpid, drep, h.ofVersion); 417 h.sw = h.controller.getOFSwitchInstance(h.thisdpid, drep, h.ofVersion);
418 +
418 h.sw.setOFVersion(h.ofVersion); 419 h.sw.setOFVersion(h.ofVersion);
419 h.sw.setFeaturesReply(h.featuresReply); 420 h.sw.setFeaturesReply(h.featuresReply);
420 h.sw.setPortDescReply(h.portDescReply); 421 h.sw.setPortDescReply(h.portDescReply);
421 h.sw.setConnected(true); 422 h.sw.setConnected(true);
422 h.sw.setChannel(h.channel); 423 h.sw.setChannel(h.channel);
423 boolean success = h.sw.connectSwitch(); 424 boolean success = h.sw.connectSwitch();
425 +
424 if (!success) { 426 if (!success) {
425 disconnectDuplicate(h); 427 disconnectDuplicate(h);
426 return; 428 return;
...@@ -432,10 +434,10 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { ...@@ -432,10 +434,10 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
432 log.info("Switch {} bound to class {}, description {}", 434 log.info("Switch {} bound to class {}, description {}",
433 new Object[] {h.sw, h.sw.getClass(), drep }); 435 new Object[] {h.sw, h.sw.getClass(), drep });
434 //Put switch in EQUAL mode until we hear back from the global registry 436 //Put switch in EQUAL mode until we hear back from the global registry
435 - log.debug("Setting new switch {} to EQUAL and sending Role request", 437 + //log.debug("Setting new switch {} to EQUAL and sending Role request",
436 - h.sw.getStringId()); 438 + // h.sw.getStringId());
437 - h.sw.activateEqualSwitch(); 439 + //h.sw.activateEqualSwitch();
438 - h.setSwitchRole(RoleState.EQUAL); 440 + //h.setSwitchRole(RoleState.EQUAL);
439 441
440 h.sw.startDriverHandshake(); 442 h.sw.startDriverHandshake();
441 h.setState(WAIT_SWITCH_DRIVER_SUB_HANDSHAKE); 443 h.setState(WAIT_SWITCH_DRIVER_SUB_HANDSHAKE);
......
1 package org.onlab.onos.of.controller.impl; 1 package org.onlab.onos.of.controller.impl;
2 2
3 +import java.util.ArrayList;
4 +import java.util.HashSet;
5 +import java.util.List;
6 +import java.util.Set;
7 +import java.util.concurrent.ConcurrentHashMap;
8 +import java.util.concurrent.locks.Lock;
9 +import java.util.concurrent.locks.ReentrantLock;
10 +
3 import org.apache.felix.scr.annotations.Activate; 11 import org.apache.felix.scr.annotations.Activate;
4 import org.apache.felix.scr.annotations.Component; 12 import org.apache.felix.scr.annotations.Component;
5 import org.apache.felix.scr.annotations.Deactivate; 13 import org.apache.felix.scr.annotations.Deactivate;
6 import org.apache.felix.scr.annotations.Service; 14 import org.apache.felix.scr.annotations.Service;
15 +import org.onlab.onos.of.controller.DefaultPacketContext;
7 import org.onlab.onos.of.controller.Dpid; 16 import org.onlab.onos.of.controller.Dpid;
8 import org.onlab.onos.of.controller.OpenFlowController; 17 import org.onlab.onos.of.controller.OpenFlowController;
9 import org.onlab.onos.of.controller.OpenFlowSwitch; 18 import org.onlab.onos.of.controller.OpenFlowSwitch;
...@@ -12,18 +21,11 @@ import org.onlab.onos.of.controller.PacketListener; ...@@ -12,18 +21,11 @@ import org.onlab.onos.of.controller.PacketListener;
12 import org.onlab.onos.of.controller.RoleState; 21 import org.onlab.onos.of.controller.RoleState;
13 import org.onlab.onos.of.controller.driver.OpenFlowAgent; 22 import org.onlab.onos.of.controller.driver.OpenFlowAgent;
14 import org.projectfloodlight.openflow.protocol.OFMessage; 23 import org.projectfloodlight.openflow.protocol.OFMessage;
24 +import org.projectfloodlight.openflow.protocol.OFPacketIn;
15 import org.projectfloodlight.openflow.protocol.OFPortStatus; 25 import org.projectfloodlight.openflow.protocol.OFPortStatus;
16 import org.slf4j.Logger; 26 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 27 import org.slf4j.LoggerFactory;
18 28
19 -import java.util.ArrayList;
20 -import java.util.HashSet;
21 -import java.util.List;
22 -import java.util.Set;
23 -import java.util.concurrent.ConcurrentHashMap;
24 -import java.util.concurrent.locks.Lock;
25 -import java.util.concurrent.locks.ReentrantLock;
26 -
27 @Component(immediate = true) 29 @Component(immediate = true)
28 @Service 30 @Service
29 public class OpenFlowControllerImpl implements OpenFlowController { 31 public class OpenFlowControllerImpl implements OpenFlowController {
...@@ -125,11 +127,14 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -125,11 +127,14 @@ public class OpenFlowControllerImpl implements OpenFlowController {
125 case PACKET_IN: 127 case PACKET_IN:
126 for (PacketListener p : ofPacketListener) { 128 for (PacketListener p : ofPacketListener) {
127 //TODO fix me! 129 //TODO fix me!
128 - p.handlePacket(null); 130 + p.handlePacket(DefaultPacketContext
131 + .packetContextFromPacketIn(this.getSwitch(dpid),
132 + (OFPacketIn) msg));
129 } 133 }
130 break; 134 break;
131 default: 135 default:
132 - log.warn("Handling message type {} not yet implemented", msg.getType()); 136 + log.warn("Handling message type {} not yet implemented {}",
137 + msg.getType(), msg);
133 } 138 }
134 } 139 }
135 140
...@@ -224,10 +229,13 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -224,10 +229,13 @@ public class OpenFlowControllerImpl implements OpenFlowController {
224 } 229 }
225 OpenFlowSwitch sw = activeEqualSwitches.remove(dpid); 230 OpenFlowSwitch sw = activeEqualSwitches.remove(dpid);
226 if (sw == null) { 231 if (sw == null) {
232 + sw = getSwitch(dpid);
233 + if (sw == null) {
227 log.error("Transition to master called on sw {}, but switch " 234 log.error("Transition to master called on sw {}, but switch "
228 + "was not found in controller-cache", dpid); 235 + "was not found in controller-cache", dpid);
229 return; 236 return;
230 } 237 }
238 + }
231 log.info("Transitioned switch {} to MASTER", dpid); 239 log.info("Transitioned switch {} to MASTER", dpid);
232 activeMasterSwitches.put(dpid, sw); 240 activeMasterSwitches.put(dpid, sw);
233 } finally { 241 } finally {
......
...@@ -84,7 +84,7 @@ class RoleManager implements RoleHandler { ...@@ -84,7 +84,7 @@ class RoleManager implements RoleHandler {
84 default: 84 default:
85 // ensuring that the only two roles sent to 1.0 switches with 85 // ensuring that the only two roles sent to 1.0 switches with
86 // Nicira role support, are MASTER and SLAVE 86 // Nicira role support, are MASTER and SLAVE
87 - roleToSend = OFNiciraControllerRole.ROLE_SLAVE; 87 + roleToSend = OFNiciraControllerRole.ROLE_OTHER;
88 log.warn("Sending Nx Role.SLAVE to switch {}.", sw); 88 log.warn("Sending Nx Role.SLAVE to switch {}.", sw);
89 } 89 }
90 int xid = sw.getNextTransactionId(); 90 int xid = sw.getNextTransactionId();
......
...@@ -50,8 +50,7 @@ public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch { ...@@ -50,8 +50,7 @@ public class OFSwitchImplOVS10 extends AbstractOpenFlowSwitch {
50 50
51 @Override 51 @Override
52 public void write(OFMessage msg) { 52 public void write(OFMessage msg) {
53 - channel.write(msg); 53 + channel.write(Collections.singletonList(msg));
54 -
55 } 54 }
56 55
57 @Override 56 @Override
......
...@@ -62,6 +62,14 @@ ...@@ -62,6 +62,14 @@
62 </dependency> 62 </dependency>
63 63
64 <dependency> 64 <dependency>
65 + <groupId>io.netty</groupId>
66 + <artifactId>netty</artifactId>
67 + <version>3.9.0.Final</version>
68 + </dependency>
69 +
70 +
71 +
72 + <dependency>
65 <groupId>com.google.guava</groupId> 73 <groupId>com.google.guava</groupId>
66 <artifactId>guava-testlib</artifactId> 74 <artifactId>guava-testlib</artifactId>
67 <version>18.0</version> 75 <version>18.0</version>
......
...@@ -2,11 +2,17 @@ package org.onlab.onos.provider.of.link.impl; ...@@ -2,11 +2,17 @@ package org.onlab.onos.provider.of.link.impl;
2 2
3 import static org.slf4j.LoggerFactory.getLogger; 3 import static org.slf4j.LoggerFactory.getLogger;
4 4
5 +import java.util.Map;
6 +import java.util.concurrent.ConcurrentHashMap;
7 +
5 import org.apache.felix.scr.annotations.Activate; 8 import org.apache.felix.scr.annotations.Activate;
6 import org.apache.felix.scr.annotations.Component; 9 import org.apache.felix.scr.annotations.Component;
7 import org.apache.felix.scr.annotations.Deactivate; 10 import org.apache.felix.scr.annotations.Deactivate;
8 import org.apache.felix.scr.annotations.Reference; 11 import org.apache.felix.scr.annotations.Reference;
9 import org.apache.felix.scr.annotations.ReferenceCardinality; 12 import org.apache.felix.scr.annotations.ReferenceCardinality;
13 +import org.onlab.onos.net.ConnectPoint;
14 +import org.onlab.onos.net.DeviceId;
15 +import org.onlab.onos.net.PortNumber;
10 import org.onlab.onos.net.link.LinkProvider; 16 import org.onlab.onos.net.link.LinkProvider;
11 import org.onlab.onos.net.link.LinkProviderRegistry; 17 import org.onlab.onos.net.link.LinkProviderRegistry;
12 import org.onlab.onos.net.link.LinkProviderService; 18 import org.onlab.onos.net.link.LinkProviderService;
...@@ -17,6 +23,10 @@ import org.onlab.onos.of.controller.OpenFlowController; ...@@ -17,6 +23,10 @@ import org.onlab.onos.of.controller.OpenFlowController;
17 import org.onlab.onos.of.controller.OpenFlowSwitchListener; 23 import org.onlab.onos.of.controller.OpenFlowSwitchListener;
18 import org.onlab.onos.of.controller.PacketContext; 24 import org.onlab.onos.of.controller.PacketContext;
19 import org.onlab.onos.of.controller.PacketListener; 25 import org.onlab.onos.of.controller.PacketListener;
26 +import org.onlab.timer.Timer;
27 +import org.projectfloodlight.openflow.protocol.OFPortConfig;
28 +import org.projectfloodlight.openflow.protocol.OFPortDesc;
29 +import org.projectfloodlight.openflow.protocol.OFPortState;
20 import org.projectfloodlight.openflow.protocol.OFPortStatus; 30 import org.projectfloodlight.openflow.protocol.OFPortStatus;
21 import org.slf4j.Logger; 31 import org.slf4j.Logger;
22 32
...@@ -37,6 +47,8 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -37,6 +47,8 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
37 47
38 private LinkProviderService providerService; 48 private LinkProviderService providerService;
39 49
50 + private final boolean useBDDP = true;
51 +
40 private final InternalLinkProvider listener = new InternalLinkProvider(); 52 private final InternalLinkProvider listener = new InternalLinkProvider();
41 53
42 /** 54 /**
...@@ -60,32 +72,61 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -60,32 +72,61 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
60 controller.removeListener(listener); 72 controller.removeListener(listener);
61 controller.removePacketListener(listener); 73 controller.removePacketListener(listener);
62 providerService = null; 74 providerService = null;
75 + Timer.getTimer().stop();
63 log.info("Stopped"); 76 log.info("Stopped");
64 } 77 }
65 78
66 79
67 private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener { 80 private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener {
68 81
82 + private final Map<Dpid, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
83 +
69 @Override 84 @Override
70 public void handlePacket(PacketContext pktCtx) { 85 public void handlePacket(PacketContext pktCtx) {
86 + LinkDiscovery ld = discoverers.get(pktCtx.dpid());
87 + if (ld == null) {
88 + return;
89 + }
90 + ld.handleLLDP(pktCtx.parsed(),
91 + pktCtx.inPort());
71 92
72 } 93 }
73 94
74 @Override 95 @Override
75 public void switchAdded(Dpid dpid) { 96 public void switchAdded(Dpid dpid) {
76 - // TODO Auto-generated method stub 97 + discoverers.put(dpid, new LinkDiscovery(controller.getSwitch(dpid),
98 + controller, providerService, useBDDP));
77 99
78 } 100 }
79 101
80 @Override 102 @Override
81 public void switchRemoved(Dpid dpid) { 103 public void switchRemoved(Dpid dpid) {
82 - // TODO Auto-generated method stub 104 + LinkDiscovery ld = this.discoverers.remove(dpid);
83 - 105 + if (ld != null) {
106 + ld.removeAllPorts();
107 + }
108 + providerService.linksVanished(
109 + DeviceId.deviceId("of:" + Long.toHexString(dpid.value())));
84 } 110 }
85 111
86 @Override 112 @Override
87 public void portChanged(Dpid dpid, OFPortStatus status) { 113 public void portChanged(Dpid dpid, OFPortStatus status) {
88 - // TODO Auto-generated method stub 114 + LinkDiscovery ld = discoverers.get(dpid);
115 + if (ld == null) {
116 + return;
117 + }
118 + final OFPortDesc port = status.getDesc();
119 + final boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
120 + !port.getConfig().contains(OFPortConfig.PORT_DOWN);
121 + if (enabled) {
122 + ld.addPort(port);
123 + } else {
124 + ConnectPoint cp = new ConnectPoint(
125 + DeviceId.deviceId("of:" + Long.toHexString(dpid.value())),
126 + PortNumber.portNumber(port.getPortNo().getPortNumber()));
127 + providerService.linksVanished(cp);
128 + ld.removePort(port.getPortNo());
129 + }
89 130
90 } 131 }
91 132
......
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
25 <dependency> 25 <dependency>
26 <groupId>io.netty</groupId> 26 <groupId>io.netty</groupId>
27 <artifactId>netty</artifactId> 27 <artifactId>netty</artifactId>
28 - <version>3.9.0.Final</version> 28 + </dependency>
29 + <dependency>
30 + <groupId>commons-lang</groupId>
31 + <artifactId>commons-lang</artifactId>
29 </dependency> 32 </dependency>
30 </dependencies> 33 </dependencies>
31 34
......
...@@ -21,6 +21,8 @@ import java.util.LinkedList; ...@@ -21,6 +21,8 @@ import java.util.LinkedList;
21 import java.util.List; 21 import java.util.List;
22 22
23 import org.apache.commons.lang.ArrayUtils; 23 import org.apache.commons.lang.ArrayUtils;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
24 26
25 27
26 /** 28 /**
...@@ -31,6 +33,7 @@ import org.apache.commons.lang.ArrayUtils; ...@@ -31,6 +33,7 @@ import org.apache.commons.lang.ArrayUtils;
31 @SuppressWarnings("rawtypes") 33 @SuppressWarnings("rawtypes")
32 public class ONLabLddp extends LLDP { 34 public class ONLabLddp extends LLDP {
33 35
36 + private static final Logger log = LoggerFactory.getLogger(ONLabLddp.class);
34 // ON.Lab OUI and OVX name for organizationally specific TLVs 37 // ON.Lab OUI and OVX name for organizationally specific TLVs
35 public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05}; 38 public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05};
36 public static final String OVX_NAME = "OpenVirteX"; 39 public static final String OVX_NAME = "OpenVirteX";
...@@ -50,7 +53,7 @@ public class ONLabLddp extends LLDP { ...@@ -50,7 +53,7 @@ public class ONLabLddp extends LLDP {
50 private static final byte CHASSIS_TLV_SUBTYPE = 4; 53 private static final byte CHASSIS_TLV_SUBTYPE = 4;
51 54
52 private static final byte PORT_TLV_TYPE = 2; 55 private static final byte PORT_TLV_TYPE = 2;
53 - private static final byte PORT_TLV_SIZE = 7; 56 + private static final byte PORT_TLV_SIZE = 5;
54 private static final byte PORT_TLV_SUBTYPE = 2; 57 private static final byte PORT_TLV_SUBTYPE = 2;
55 58
56 private static final byte TTL_TLV_TYPE = 3; 59 private static final byte TTL_TLV_TYPE = 3;
...@@ -60,7 +63,7 @@ public class ONLabLddp extends LLDP { ...@@ -60,7 +63,7 @@ public class ONLabLddp extends LLDP {
60 // 4 = OUI (3) + subtype (1) 63 // 4 = OUI (3) + subtype (1)
61 private static final byte NAME_TLV_SIZE = (byte) (4 + ONLabLddp.OVX_NAME.length()); 64 private static final byte NAME_TLV_SIZE = (byte) (4 + ONLabLddp.OVX_NAME.length());
62 private static final byte NAME_TLV_SUBTYPE = 1; 65 private static final byte NAME_TLV_SUBTYPE = 1;
63 - private static final short NAME_TLV_OFFSET = 32; 66 + private static final short NAME_TLV_OFFSET = 34;
64 private static final short NAME_TLV_HEADER = (short) ((NAME_TLV_TYPE << 9) | NAME_TLV_SIZE); 67 private static final short NAME_TLV_HEADER = (short) ((NAME_TLV_TYPE << 9) | NAME_TLV_SIZE);
65 // Contents of full name TLV 68 // Contents of full name TLV
66 private static final byte[] NAME_TLV = ByteBuffer.allocate(NAME_TLV_SIZE + 2) 69 private static final byte[] NAME_TLV = ByteBuffer.allocate(NAME_TLV_SIZE + 2)
...@@ -85,7 +88,7 @@ public class ONLabLddp extends LLDP { ...@@ -85,7 +88,7 @@ public class ONLabLddp extends LLDP {
85 // Default switch, port number and TTL 88 // Default switch, port number and TTL
86 private static final byte[] DEFAULT_DPID = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 89 private static final byte[] DEFAULT_DPID = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00 }; 90 0x00, 0x00 };
88 - private static final short DEFAULT_PORT = 0; 91 + private static final int DEFAULT_PORT = 0;
89 private static final short DEFAULT_TTL = 120; // in seconds 92 private static final short DEFAULT_TTL = 120; // in seconds
90 93
91 // Minimum and OVX-generated LLDP packet sizes 94 // Minimum and OVX-generated LLDP packet sizes
...@@ -97,7 +100,7 @@ public class ONLabLddp extends LLDP { ...@@ -97,7 +100,7 @@ public class ONLabLddp extends LLDP {
97 // Field offsets in OVX-generated LLDP 100 // Field offsets in OVX-generated LLDP
98 private static final short ETHERTYPE_OFFSET = 12; 101 private static final short ETHERTYPE_OFFSET = 12;
99 private static final short PORT_OFFSET = 26; 102 private static final short PORT_OFFSET = 26;
100 - private static final short DPID_OFFSET = 54; 103 + private static final short DPID_OFFSET = 56;
101 104
102 // Private member fields 105 // Private member fields
103 // Byte arrays for TLV information string 106 // Byte arrays for TLV information string
...@@ -167,10 +170,10 @@ public class ONLabLddp extends LLDP { ...@@ -167,10 +170,10 @@ public class ONLabLddp extends LLDP {
167 * 170 *
168 * @param portNumber the port number 171 * @param portNumber the port number
169 */ 172 */
170 - private void setPortTLV(final long portNumber) { 173 + private void setPortTLV(final int portNumber) {
171 this.bb = ByteBuffer.wrap(this.portId); 174 this.bb = ByteBuffer.wrap(this.portId);
172 this.bb.put(PORT_TLV_SUBTYPE); 175 this.bb.put(PORT_TLV_SUBTYPE);
173 - this.bb.putLong(portNumber); 176 + this.bb.putInt(portNumber);
174 177
175 this.portTLV.setLength(PORT_TLV_SIZE); 178 this.portTLV.setLength(PORT_TLV_SIZE);
176 this.portTLV.setType(PORT_TLV_TYPE); 179 this.portTLV.setType(PORT_TLV_TYPE);
...@@ -240,8 +243,8 @@ public class ONLabLddp extends LLDP { ...@@ -240,8 +243,8 @@ public class ONLabLddp extends LLDP {
240 * 243 *
241 * @param port the port instance 244 * @param port the port instance
242 */ 245 */
243 - public void setPort(long port) { 246 + public void setPort(int port) {
244 - long portNumber = port; 247 + int portNumber = port;
245 this.setPortTLV(portNumber); 248 this.setPortTLV(portNumber);
246 } 249 }
247 250
...@@ -335,7 +338,7 @@ public class ONLabLddp extends LLDP { ...@@ -335,7 +338,7 @@ public class ONLabLddp extends LLDP {
335 * @param packet 338 * @param packet
336 * @return Dpid and port 339 * @return Dpid and port
337 */ 340 */
338 - /* public static long parseLLDP(final byte[] packet) { 341 + public static DPIDandPort parseLLDP(final byte[] packet) {
339 final ByteBuffer bb = ByteBuffer.wrap(packet); 342 final ByteBuffer bb = ByteBuffer.wrap(packet);
340 343
341 // Extra offset due to VLAN tag 344 // Extra offset due to VLAN tag
...@@ -345,10 +348,30 @@ public class ONLabLddp extends LLDP { ...@@ -345,10 +348,30 @@ public class ONLabLddp extends LLDP {
345 offset = 4; 348 offset = 4;
346 } 349 }
347 350
348 - final short port = bb.getLong(PORT_OFFSET + offset); 351 + final int port = bb.getInt(PORT_OFFSET + offset);
349 final long dpid = bb.getLong(DPID_OFFSET + offset); 352 final long dpid = bb.getLong(DPID_OFFSET + offset);
350 353
351 - return dpid 354 + return new DPIDandPort(dpid, port);
352 } 355 }
353 - */ 356 +
357 + public static class DPIDandPort {
358 +
359 + private final long dpid;
360 + private final int port;
361 +
362 + public DPIDandPort(long dpid, int port) {
363 + this.dpid = dpid;
364 + this.port = port;
365 + }
366 +
367 + public long getDpid() {
368 + return this.dpid;
369 + }
370 +
371 + public int getPort() {
372 + return this.port;
373 + }
374 +
375 + }
376 +
354 } 377 }
......
1 +package org.onlab.timer;
2 +
3 +import org.jboss.netty.util.HashedWheelTimer;
4 +
5 +
6 +public final class Timer {
7 +
8 + private Timer() {}
9 +
10 + private static HashedWheelTimer timer;
11 +
12 + public static HashedWheelTimer getTimer() {
13 + if (Timer.timer == null) {
14 + Timer.timer = new HashedWheelTimer();
15 + Timer.timer.start();
16 + }
17 + return Timer.timer;
18 + }
19 +
20 +}