alshabib

started adding link discovery

package org.onlab.onos.of.controller;
import java.util.Collections;
import org.onlab.packet.Ethernet;
import org.projectfloodlight.openflow.protocol.OFPacketIn;
import org.projectfloodlight.openflow.protocol.OFPacketOut;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.types.OFBufferId;
import org.projectfloodlight.openflow.types.OFPort;
public final class DefaultPacketContext implements PacketContext {
......@@ -11,7 +15,7 @@ public final class DefaultPacketContext implements PacketContext {
private boolean isBuilt = false;
private final OpenFlowSwitch sw;
private final OFPacketIn pktin;
private final OFPacketOut pktout = null;
private OFPacketOut pktout = null;
private DefaultPacketContext(OpenFlowSwitch s, OFPacketIn pkt) {
this.sw = s;
......@@ -39,20 +43,32 @@ public final class DefaultPacketContext implements PacketContext {
@Override
public void build(Ethernet ethFrame, OFPort outPort) {
// TODO Auto-generated method stub
if (isBuilt) {
return;
}
OFPacketOut.Builder builder = sw.factory().buildPacketOut();
OFAction act = sw.factory().actions()
.buildOutput()
.setPort(OFPort.of(outPort.getPortNumber()))
.build();
pktout = builder.setXid(pktin.getXid())
.setBufferId(OFBufferId.NO_BUFFER)
.setActions(Collections.singletonList(act))
.setData(ethFrame.serialize())
.build();
isBuilt = true;
}
@Override
public Ethernet parsed() {
// TODO Auto-generated method stub
return null;
Ethernet eth = new Ethernet();
eth.deserialize(pktin.getData(), 0, pktin.getTotalLen());
return eth;
}
@Override
public Dpid dpid() {
// TODO Auto-generated method stub
return null;
return new Dpid(sw.getId());
}
public static PacketContext packetContextFromPacketIn(OpenFlowSwitch s, OFPacketIn pkt) {
......
......@@ -12,9 +12,12 @@ import org.onlab.onos.net.link.LinkProviderRegistry;
import org.onlab.onos.net.link.LinkProviderService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.of.controller.Dpid;
import org.onlab.onos.of.controller.OpenFlowController;
import org.onlab.onos.of.controller.OpenFlowSwitchListener;
import org.onlab.onos.of.controller.PacketContext;
import org.onlab.onos.of.controller.PacketListener;
import org.projectfloodlight.openflow.protocol.OFPortStatus;
import org.slf4j.Logger;
/**
......@@ -34,7 +37,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
private LinkProviderService providerService;
private final PacketListener listener = new InternalLinkProvider();
private final InternalLinkProvider listener = new InternalLinkProvider();
/**
* Creates an OpenFlow link provider.
......@@ -46,6 +49,7 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
@Activate
public void activate() {
providerService = providerRegistry.register(this);
controller.addListener(listener);
controller.addPacketListener(0, listener);
log.info("Started");
}
......@@ -53,19 +57,38 @@ public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvid
@Deactivate
public void deactivate() {
providerRegistry.unregister(this);
controller.removeListener(listener);
controller.removePacketListener(listener);
providerService = null;
log.info("Stopped");
}
private class InternalLinkProvider implements PacketListener {
private class InternalLinkProvider implements PacketListener, OpenFlowSwitchListener {
@Override
public void handlePacket(PacketContext pktCtx) {
}
@Override
public void switchAdded(Dpid dpid) {
// TODO Auto-generated method stub
}
@Override
public void switchRemoved(Dpid dpid) {
// TODO Auto-generated method stub
}
@Override
public void portChanged(Dpid dpid, OFPortStatus status) {
// TODO Auto-generated method stub
}
}
}
......
......@@ -23,6 +23,11 @@
<version>17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.9.0.Final</version>
</dependency>
</dependencies>
</project>
......
......@@ -29,7 +29,7 @@ import org.apache.commons.lang.ArrayUtils;
*
*/
@SuppressWarnings("rawtypes")
public class OVXLLDP extends LLDP {
public class ONLabLddp extends LLDP {
// ON.Lab OUI and OVX name for organizationally specific TLVs
public static final byte[] ONLAB_OUI = {(byte) 0xa4, 0x23, 0x05};
......@@ -58,7 +58,7 @@ public class OVXLLDP extends LLDP {
private static final byte NAME_TLV_TYPE = 127;
// 4 = OUI (3) + subtype (1)
private static final byte NAME_TLV_SIZE = (byte) (4 + OVXLLDP.OVX_NAME.length());
private static final byte NAME_TLV_SIZE = (byte) (4 + ONLabLddp.OVX_NAME.length());
private static final byte NAME_TLV_SUBTYPE = 1;
private static final short NAME_TLV_OFFSET = 32;
private static final short NAME_TLV_HEADER = (short) ((NAME_TLV_TYPE << 9) | NAME_TLV_SIZE);
......@@ -119,7 +119,7 @@ public class OVXLLDP extends LLDP {
/**
* Instantiates a new OVX LDDP message.
*/
public OVXLLDP() {
public ONLabLddp() {
// Create TLVs
this.chassisTLV = new LLDPTLV();
this.portTLV = new LLDPTLV();
......@@ -140,7 +140,7 @@ public class OVXLLDP extends LLDP {
this.setChassisTLV(DEFAULT_DPID);
this.setPortTLV(DEFAULT_PORT);
this.setTTLTLV(DEFAULT_TTL);
this.setOUIName(OVXLLDP.OVX_NAME);
this.setOUIName(ONLabLddp.OVX_NAME);
this.setOUIDpid(DEFAULT_DPID);
}
......@@ -198,7 +198,7 @@ public class OVXLLDP extends LLDP {
*/
private void setOUIName(final String name) {
this.bb = ByteBuffer.wrap(ouiName);
this.bb.put(OVXLLDP.ONLAB_OUI);
this.bb.put(ONLabLddp.ONLAB_OUI);
this.bb.put(NAME_TLV_SUBTYPE);
this.bb.put(name.getBytes());
......@@ -214,7 +214,7 @@ public class OVXLLDP extends LLDP {
*/
private void setOUIDpid(final byte[] dpid) {
this.bb = ByteBuffer.wrap(ouiDpid);
this.bb.put(OVXLLDP.ONLAB_OUI);
this.bb.put(ONLabLddp.ONLAB_OUI);
this.bb.put(DPID_TLV_SUBTYPE);
this.bb.put(dpid);
......@@ -272,9 +272,9 @@ public class OVXLLDP extends LLDP {
final byte[] dst = new byte[6];
bb.get(dst);
if (!(Arrays.equals(dst, OVXLLDP.LLDP_NICIRA)
|| Arrays.equals(dst, OVXLLDP.LLDP_MULTICAST) || Arrays.equals(
dst, OVXLLDP.BDDP_MULTICAST))) {
if (!(Arrays.equals(dst, ONLabLddp.LLDP_NICIRA)
|| Arrays.equals(dst, ONLabLddp.LLDP_MULTICAST) || Arrays.equals(
dst, ONLabLddp.BDDP_MULTICAST))) {
return false;
}
......