alshabib

started adding link discovery

1 package org.onlab.onos.of.controller; 1 package org.onlab.onos.of.controller;
2 2
3 +import java.util.Collections;
4 +
3 import org.onlab.packet.Ethernet; 5 import org.onlab.packet.Ethernet;
4 import org.projectfloodlight.openflow.protocol.OFPacketIn; 6 import org.projectfloodlight.openflow.protocol.OFPacketIn;
5 import org.projectfloodlight.openflow.protocol.OFPacketOut; 7 import org.projectfloodlight.openflow.protocol.OFPacketOut;
8 +import org.projectfloodlight.openflow.protocol.action.OFAction;
9 +import org.projectfloodlight.openflow.types.OFBufferId;
6 import org.projectfloodlight.openflow.types.OFPort; 10 import org.projectfloodlight.openflow.types.OFPort;
7 11
8 public final class DefaultPacketContext implements PacketContext { 12 public final class DefaultPacketContext implements PacketContext {
...@@ -11,7 +15,7 @@ public final class DefaultPacketContext implements PacketContext { ...@@ -11,7 +15,7 @@ public final class DefaultPacketContext implements PacketContext {
11 private boolean isBuilt = false; 15 private boolean isBuilt = false;
12 private final OpenFlowSwitch sw; 16 private final OpenFlowSwitch sw;
13 private final OFPacketIn pktin; 17 private final OFPacketIn pktin;
14 - private final OFPacketOut pktout = null; 18 + private OFPacketOut pktout = null;
15 19
16 private DefaultPacketContext(OpenFlowSwitch s, OFPacketIn pkt) { 20 private DefaultPacketContext(OpenFlowSwitch s, OFPacketIn pkt) {
17 this.sw = s; 21 this.sw = s;
...@@ -39,20 +43,32 @@ public final class DefaultPacketContext implements PacketContext { ...@@ -39,20 +43,32 @@ public final class DefaultPacketContext implements PacketContext {
39 43
40 @Override 44 @Override
41 public void build(Ethernet ethFrame, OFPort outPort) { 45 public void build(Ethernet ethFrame, OFPort outPort) {
42 - // TODO Auto-generated method stub 46 + if (isBuilt) {
43 - 47 + return;
48 + }
49 + OFPacketOut.Builder builder = sw.factory().buildPacketOut();
50 + OFAction act = sw.factory().actions()
51 + .buildOutput()
52 + .setPort(OFPort.of(outPort.getPortNumber()))
53 + .build();
54 + pktout = builder.setXid(pktin.getXid())
55 + .setBufferId(OFBufferId.NO_BUFFER)
56 + .setActions(Collections.singletonList(act))
57 + .setData(ethFrame.serialize())
58 + .build();
59 + isBuilt = true;
44 } 60 }
45 61
46 @Override 62 @Override
47 public Ethernet parsed() { 63 public Ethernet parsed() {
48 - // TODO Auto-generated method stub 64 + Ethernet eth = new Ethernet();
49 - return null; 65 + eth.deserialize(pktin.getData(), 0, pktin.getTotalLen());
66 + return eth;
50 } 67 }
51 68
52 @Override 69 @Override
53 public Dpid dpid() { 70 public Dpid dpid() {
54 - // TODO Auto-generated method stub 71 + return new Dpid(sw.getId());
55 - return null;
56 } 72 }
57 73
58 public static PacketContext packetContextFromPacketIn(OpenFlowSwitch s, OFPacketIn pkt) { 74 public static PacketContext packetContextFromPacketIn(OpenFlowSwitch s, OFPacketIn pkt) {
......
...@@ -12,9 +12,12 @@ import org.onlab.onos.net.link.LinkProviderRegistry; ...@@ -12,9 +12,12 @@ import org.onlab.onos.net.link.LinkProviderRegistry;
12 import org.onlab.onos.net.link.LinkProviderService; 12 import org.onlab.onos.net.link.LinkProviderService;
13 import org.onlab.onos.net.provider.AbstractProvider; 13 import org.onlab.onos.net.provider.AbstractProvider;
14 import org.onlab.onos.net.provider.ProviderId; 14 import org.onlab.onos.net.provider.ProviderId;
15 +import org.onlab.onos.of.controller.Dpid;
15 import org.onlab.onos.of.controller.OpenFlowController; 16 import org.onlab.onos.of.controller.OpenFlowController;
17 +import org.onlab.onos.of.controller.OpenFlowSwitchListener;
16 import org.onlab.onos.of.controller.PacketContext; 18 import org.onlab.onos.of.controller.PacketContext;
17 import org.onlab.onos.of.controller.PacketListener; 19 import org.onlab.onos.of.controller.PacketListener;
20 +import org.projectfloodlight.openflow.protocol.OFPortStatus;
18 import org.slf4j.Logger; 21 import org.slf4j.Logger;
19 22
20 /** 23 /**
...@@ -34,7 +37,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -34,7 +37,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
34 37
35 private LinkProviderService providerService; 38 private LinkProviderService providerService;
36 39
37 - private final PacketListener listener = new InternalLinkProvider(); 40 + private final InternalLinkProvider listener = new InternalLinkProvider();
38 41
39 /** 42 /**
40 * Creates an OpenFlow link provider. 43 * Creates an OpenFlow link provider.
...@@ -46,6 +49,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -46,6 +49,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
46 @Activate 49 @Activate
47 public void activate() { 50 public void activate() {
48 providerService = providerRegistry.register(this); 51 providerService = providerRegistry.register(this);
52 + controller.addListener(listener);
49 controller.addPacketListener(0, listener); 53 controller.addPacketListener(0, listener);
50 log.info("Started"); 54 log.info("Started");
51 } 55 }
...@@ -53,19 +57,38 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid ...@@ -53,19 +57,38 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
53 @Deactivate 57 @Deactivate
54 public void deactivate() { 58 public void deactivate() {
55 providerRegistry.unregister(this); 59 providerRegistry.unregister(this);
60 + controller.removeListener(listener);
56 controller.removePacketListener(listener); 61 controller.removePacketListener(listener);
57 providerService = null; 62 providerService = null;
58 log.info("Stopped"); 63 log.info("Stopped");
59 } 64 }
60 65
61 66
62 - private class InternalLinkProvider implements PacketListener { 67 + private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener {
63 68
64 @Override 69 @Override
65 public void handlePacket(PacketContext pktCtx) { 70 public void handlePacket(PacketContext pktCtx) {
66 71
67 } 72 }
68 73
74 + @Override
75 + public void switchAdded(Dpid dpid) {
76 + // TODO Auto-generated method stub
77 +
78 + }
79 +
80 + @Override
81 + public void switchRemoved(Dpid dpid) {
82 + // TODO Auto-generated method stub
83 +
84 + }
85 +
86 + @Override
87 + public void portChanged(Dpid dpid, OFPortStatus status) {
88 + // TODO Auto-generated method stub
89 +
90 + }
91 +
69 } 92 }
70 93
71 } 94 }
......
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
23 <version>17.0</version> 23 <version>17.0</version>
24 <scope>test</scope> 24 <scope>test</scope>
25 </dependency> 25 </dependency>
26 + <dependency>
27 + <groupId>io.netty</groupId>
28 + <artifactId>netty</artifactId>
29 + <version>3.9.0.Final</version>
30 + </dependency>
26 </dependencies> 31 </dependencies>
27 32
28 </project> 33 </project>
......
...@@ -29,7 +29,7 @@ import org.apache.commons.lang.ArrayUtils; ...@@ -29,7 +29,7 @@ import org.apache.commons.lang.ArrayUtils;
29 * 29 *
30 */ 30 */
31 @SuppressWarnings("rawtypes") 31 @SuppressWarnings("rawtypes")
32 -public class OVXLLDP extends LLDP { 32 +public class ONLabLddp extends LLDP {
33 33
34 // ON.Lab OUI and OVX name for organizationally specific TLVs 34 // ON.Lab OUI and OVX name for organizationally specific TLVs
35 public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05}; 35 public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05};
...@@ -58,7 +58,7 @@ public class OVXLLDP extends LLDP { ...@@ -58,7 +58,7 @@ public class OVXLLDP extends LLDP {
58 58
59 private static final byte NAME_TLV_TYPE = 127; 59 private static final byte NAME_TLV_TYPE = 127;
60 // 4 = OUI (3) + subtype (1) 60 // 4 = OUI (3) + subtype (1)
61 - private static final byte NAME_TLV_SIZE = (byte) (4 + OVXLLDP.OVX_NAME.length()); 61 + private static final byte NAME_TLV_SIZE = (byte) (4 + ONLabLddp.OVX_NAME.length());
62 private static final byte NAME_TLV_SUBTYPE = 1; 62 private static final byte NAME_TLV_SUBTYPE = 1;
63 private static final short NAME_TLV_OFFSET = 32; 63 private static final short NAME_TLV_OFFSET = 32;
64 private static final short NAME_TLV_HEADER = (short) ((NAME_TLV_TYPE << 9) | NAME_TLV_SIZE); 64 private static final short NAME_TLV_HEADER = (short) ((NAME_TLV_TYPE << 9) | NAME_TLV_SIZE);
...@@ -119,7 +119,7 @@ public class OVXLLDP extends LLDP { ...@@ -119,7 +119,7 @@ public class OVXLLDP extends LLDP {
119 /** 119 /**
120 * Instantiates a new OVX LDDP message. 120 * Instantiates a new OVX LDDP message.
121 */ 121 */
122 - public OVXLLDP() { 122 + public ONLabLddp() {
123 // Create TLVs 123 // Create TLVs
124 this.chassisTLV = new LLDPTLV(); 124 this.chassisTLV = new LLDPTLV();
125 this.portTLV = new LLDPTLV(); 125 this.portTLV = new LLDPTLV();
...@@ -140,7 +140,7 @@ public class OVXLLDP extends LLDP { ...@@ -140,7 +140,7 @@ public class OVXLLDP extends LLDP {
140 this.setChassisTLV(DEFAULT_DPID); 140 this.setChassisTLV(DEFAULT_DPID);
141 this.setPortTLV(DEFAULT_PORT); 141 this.setPortTLV(DEFAULT_PORT);
142 this.setTTLTLV(DEFAULT_TTL); 142 this.setTTLTLV(DEFAULT_TTL);
143 - this.setOUIName(OVXLLDP.OVX_NAME); 143 + this.setOUIName(ONLabLddp.OVX_NAME);
144 this.setOUIDpid(DEFAULT_DPID); 144 this.setOUIDpid(DEFAULT_DPID);
145 } 145 }
146 146
...@@ -198,7 +198,7 @@ public class OVXLLDP extends LLDP { ...@@ -198,7 +198,7 @@ public class OVXLLDP extends LLDP {
198 */ 198 */
199 private void setOUIName(final String name) { 199 private void setOUIName(final String name) {
200 this.bb = ByteBuffer.wrap(ouiName); 200 this.bb = ByteBuffer.wrap(ouiName);
201 - this.bb.put(OVXLLDP.ONLAB_OUI); 201 + this.bb.put(ONLabLddp.ONLAB_OUI);
202 this.bb.put(NAME_TLV_SUBTYPE); 202 this.bb.put(NAME_TLV_SUBTYPE);
203 this.bb.put(name.getBytes()); 203 this.bb.put(name.getBytes());
204 204
...@@ -214,7 +214,7 @@ public class OVXLLDP extends LLDP { ...@@ -214,7 +214,7 @@ public class OVXLLDP extends LLDP {
214 */ 214 */
215 private void setOUIDpid(final byte[] dpid) { 215 private void setOUIDpid(final byte[] dpid) {
216 this.bb = ByteBuffer.wrap(ouiDpid); 216 this.bb = ByteBuffer.wrap(ouiDpid);
217 - this.bb.put(OVXLLDP.ONLAB_OUI); 217 + this.bb.put(ONLabLddp.ONLAB_OUI);
218 this.bb.put(DPID_TLV_SUBTYPE); 218 this.bb.put(DPID_TLV_SUBTYPE);
219 this.bb.put(dpid); 219 this.bb.put(dpid);
220 220
...@@ -272,9 +272,9 @@ public class OVXLLDP extends LLDP { ...@@ -272,9 +272,9 @@ public class OVXLLDP extends LLDP {
272 final byte[] dst = new byte[6]; 272 final byte[] dst = new byte[6];
273 bb.get(dst); 273 bb.get(dst);
274 274
275 - if (!(Arrays.equals(dst, OVXLLDP.LLDP_NICIRA) 275 + if (!(Arrays.equals(dst, ONLabLddp.LLDP_NICIRA)
276 - || Arrays.equals(dst, OVXLLDP.LLDP_MULTICAST) || Arrays.equals( 276 + || Arrays.equals(dst, ONLabLddp.LLDP_MULTICAST) || Arrays.equals(
277 - dst, OVXLLDP.BDDP_MULTICAST))) { 277 + dst, ONLabLddp.BDDP_MULTICAST))) {
278 278
279 return false; 279 return false;
280 } 280 }
......