Praseed Balakrishnan

Discover LINC-OE switch and ports.

......@@ -9,7 +9,7 @@ public interface Device extends Element {
* Coarse classification of the type of the infrastructure device.
*/
public enum Type {
SWITCH, ROUTER, FIREWALL, BALANCER, IPS, IDS, CONTROLLER, OTHER
SWITCH, ROUTER, ROADM, FIREWALL, BALANCER, IPS, IDS, CONTROLLER, OTHER
}
/**
......
......@@ -30,7 +30,7 @@
<groupId>org.projectfloodlight</groupId>
<artifactId>openflowj</artifactId>
<!-- FIXME once experimenter gets merged to upstream -->
<version>0.3.8-optical_experimenter2</version>
<version>0.3.8-optical_experimenter3</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
......
......@@ -112,4 +112,13 @@ public interface OpenFlowSwitch {
*/
void returnRoleAssertFailure(RoleState role);
/**
* Indicates if this switch is optical.
*
* @return true if optical
*/
public boolean isOptical();
}
......
......@@ -374,4 +374,9 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
return this.desc.getSerialNum();
}
@Override
public boolean isOptical() {
return false;
}
}
......
......@@ -399,12 +399,12 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
h.sw.setPortDescReply(h.portDescReply);
h.sw.setConnected(true);
h.sw.setChannel(h.channel);
boolean success = h.sw.connectSwitch();
if (!success) {
disconnectDuplicate(h);
return;
}
// boolean success = h.sw.connectSwitch();
//
// if (!success) {
// disconnectDuplicate(h);
// return;
// }
// set switch information
......@@ -462,6 +462,8 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
throws IOException, SwitchStateException {
if (m.getType() == OFType.ECHO_REQUEST) {
processOFEchoRequest(h, (OFEchoRequest) m);
} else if (m.getType() == OFType.ECHO_REPLY) {
processOFEchoReply(h, (OFEchoReply) m);
} else if (m.getType() == OFType.ROLE_REPLY) {
h.sw.handleRole(m);
} else if (m.getType() == OFType.ERROR) {
......@@ -479,6 +481,12 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
} else {
h.sw.processDriverHandshakeMessage(m);
if (h.sw.isDriverHandshakeComplete()) {
boolean success = h.sw.connectSwitch();
if (!success) {
disconnectDuplicate(h);
return;
}
h.setState(ACTIVE);
}
}
......
......@@ -59,7 +59,7 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
String sw = desc.getSwDesc();
if (sw.startsWith("LINC-OE")) {
log.debug("Optical Emulator LINC-OE with DPID:{} found..", dpid);
log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
return new OFOpticalSwitchImplLINC13(dpid, desc);
}
......
......@@ -6,6 +6,7 @@ import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeNotStar
import org.onlab.onos.openflow.controller.Dpid;
import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch;
import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus;
import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply;
import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
......@@ -14,7 +15,10 @@ import org.projectfloodlight.openflow.protocol.OFMatchV3;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFOxmList;
import org.projectfloodlight.openflow.protocol.OFPortDesc;
import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;
import org.projectfloodlight.openflow.protocol.OFPortOptical;
import org.projectfloodlight.openflow.protocol.OFStatsReply;
import org.projectfloodlight.openflow.protocol.OFStatsType;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
......@@ -43,12 +47,13 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
private final AtomicBoolean driverHandshakeComplete;
private long barrierXidToWaitFor = -1;
private OFPortDescStatsReply wPorts;
private final Logger log =
LoggerFactory.getLogger(OFOpticalSwitchImplLINC13.class);
OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) {
super(dpid);
//setAttribute("optical", "true");
driverHandshakeComplete = new AtomicBoolean(false);
setSwitchDescription(desc);
}
......@@ -62,7 +67,7 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
@Override
public void startDriverHandshake() {
log.debug("Starting driver handshake for sw {}", getStringId());
log.warn("Starting driver handshake for sw {}", getStringId());
if (startDriverHandshakeCalled) {
throw new SwitchDriverSubHandshakeAlreadyStarted();
}
......@@ -70,6 +75,8 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
try {
sendHandshakeOFExperimenterPortDescRequest();
} catch (IOException e) {
log.error("LINC-OE exception while sending experimenter port desc:",
e.getMessage());
e.printStackTrace();
}
}
......@@ -84,7 +91,7 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
@Override
public void processDriverHandshakeMessage(OFMessage m) {
if (!startDriverHandshakeCalled) {
if (!startDriverHandshakeCalled) {
throw new SwitchDriverSubHandshakeNotStarted();
}
if (driverHandshakeComplete.get()) {
......@@ -109,38 +116,49 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
case PACKET_IN:
break;
case PORT_STATUS:
log.warn("****LINC-OE Port Status {} {}", getStringId(), m);
processOFPortStatus((OFCircuitPortStatus) m);
break;
case QUEUE_GET_CONFIG_REPLY:
break;
case ROLE_REPLY:
break;
case STATS_REPLY:
log.debug("LINC-OE : Received stats reply message {}", m);
processHandshakeOFExperimenterPortDescRequest(
(OFCircuitPortsReply) m);
driverHandshakeComplete.set(true);
try {
OFStatsReply stats = (OFStatsReply) m;
if (stats.getStatsType() == OFStatsType.EXPERIMENTER) {
log.warn("LINC-OE : Received stats reply message {}", m);
processHandshakeOFExperimenterPortDescRequest(
(OFCircuitPortsReply) m);
driverHandshakeComplete.set(true);
}
/*try {
testMA();
testReverseMA();
} catch (IOException e) {
e.printStackTrace();
}
}*/
break;
default:
log.debug("Received message {} during switch-driver " +
"subhandshake " + "from switch {} ... " +
"Ignoring message", m,
getStringId());
log.warn("Received message {} during switch-driver " +
"subhandshake " + "from switch {} ... " +
"Ignoring message", m,
getStringId());
}
}
//Todo
public void processOFPortStatus(OFCircuitPortStatus ps) {
log.debug("LINC-OE ..OF Port Status :", ps);
}
private void processHandshakeOFExperimenterPortDescRequest(
OFCircuitPortsReply sr) {
Collection<OFPortOptical> entries = sr.getEntries();
List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size());
for (OFPortOptical entry : entries) {
log.warn("LINC:OE port message {}", entry.toString());
ofPortDescList.add(factory().buildPortDesc().
setPortNo(entry.getPortNo())
.setConfig(entry.getConfig())
......@@ -148,11 +166,16 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
.setHwAddr(entry.getHwAddr())
.setName(entry.getName())
.build());
}
setPortDescReply(factory().buildPortDescStatsReply().
setExperimenterPortDescReply(factory().buildPortDescStatsReply().
setEntries(ofPortDescList).build());
}
private void setExperimenterPortDescReply(OFPortDescStatsReply reply) {
wPorts = reply;
}
private void sendHandshakeOFExperimenterPortDescRequest() throws
IOException {
......@@ -160,11 +183,22 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
OFCircuitPortsRequest circuitPortsRequest = factory()
.buildCircuitPortsRequest().setXid(getNextTransactionId())
.build();
log.debug("LINC-OE : Sending experimented circuit port stats " +
"message " +
"{}",
circuitPortsRequest.toString());
sendMsg(Collections.<OFMessage>singletonList(circuitPortsRequest));
log.warn("LINC-OE : Sending experimented circuit port stats " +
"message " +
"{}",
circuitPortsRequest.toString());
this.write(Collections.<OFMessage>singletonList(circuitPortsRequest));
}
@Override
public List<OFPortDesc> getPorts() {
List<OFPortDesc> portEntries = new ArrayList<>();
portEntries.addAll(ports.getEntries());
if (wPorts != null) {
portEntries.addAll(wPorts.getEntries());
}
return Collections.unmodifiableList(portEntries);
}
......@@ -533,7 +567,7 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
@Override
public void write(OFMessage msg) {
this.sendMsg(msg);
this.channel.write(Collections.singletonList(msg));
}
@Override
......@@ -546,4 +580,10 @@ public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
return false;
}
@Override
public boolean isOptical() {
return true;
}
}
......
......@@ -165,6 +165,11 @@ public class RoleManagerTest {
}
@Override
public boolean isOptical() {
return false;
}
@Override
public void setAgent(OpenFlowAgent agent) {
}
......
......@@ -118,8 +118,10 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
DeviceId did = deviceId(uri(dpid));
OpenFlowSwitch sw = controller.getSwitch(dpid);
Device.Type deviceType = sw.isOptical() ? Device.Type.ROADM :
Device.Type.SWITCH;
DeviceDescription description =
new DefaultDeviceDescription(did.uri(), Device.Type.SWITCH,
new DefaultDeviceDescription(did.uri(), deviceType,
sw.manfacturerDescription(),
sw.hardwareDescription(),
sw.softwareDescription(),
......
......@@ -360,6 +360,11 @@ public class OpenFlowDeviceProviderTest {
public void returnRoleAssertFailure(RoleState role) {
}
@Override
public boolean isOptical() {
return false;
}
}
}
......
......@@ -467,5 +467,10 @@ public class OpenFlowLinkProviderTest {
public void returnRoleAssertFailure(RoleState role) {
}
@Override
public boolean isOptical() {
return false;
}
}
}
......
......@@ -398,6 +398,11 @@ public class OpenFlowPacketProviderTest {
public void returnRoleAssertFailure(RoleState role) {
}
@Override
public boolean isOptical() {
return false;
}
}
}
......