Ray Milkey

ONOS-535 - capture and display ip address and port of switches

[Merge from master]

Change-Id: I1671113b35853e258986568cec3a385c281e1147
(cherry picked from commit e53f171f)
......@@ -142,4 +142,9 @@ public interface OpenFlowSwitch {
*/
public boolean isOptical();
/**
* Identifies the channel used to communicate with the switch.
*/
public String channelId();
}
......
......@@ -17,11 +17,15 @@
package org.onosproject.openflow.controller.driver;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.netty.channel.Channel;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onosproject.openflow.controller.Dpid;
import org.onosproject.openflow.controller.RoleState;
import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
......@@ -48,6 +52,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
protected final Logger log = LoggerFactory.getLogger(getClass());
protected Channel channel;
protected String channelId;
private boolean connected;
protected boolean startDriverHandshakeCalled = false;
......@@ -123,8 +128,24 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver {
@Override
public final void setChannel(Channel channel) {
this.channel = channel;
final SocketAddress address = channel.getRemoteAddress();
if (address instanceof InetSocketAddress) {
final InetSocketAddress inetAddress = (InetSocketAddress) address;
final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
if (ipAddress.version() == Ip4Address.VERSION) {
channelId = ipAddress.toString() + ':' + inetAddress.getPort();
} else {
channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
}
}
};
@Override
public String channelId() {
return channelId;
}
//************************
// Switch features related
//************************
......
......@@ -300,5 +300,11 @@ public class RoleManagerTest {
failed = requested;
}
@Override
public String channelId() {
return "1.2.3.4:1";
}
}
}
......
......@@ -186,8 +186,12 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
Device.Type deviceType = sw.isOptical() ? Device.Type.ROADM :
Device.Type.SWITCH;
ChassisId cId = new ChassisId(dpid.value());
SparseAnnotations annotations = DefaultAnnotations.builder()
.set("protocol", sw.factory().getVersion().toString()).build();
.set("protocol", sw.factory().getVersion().toString())
.set("channelId", sw.channelId())
.build();
DeviceDescription description =
new DefaultDeviceDescription(did.uri(), deviceType,
sw.manfacturerDescription(),
......
......@@ -383,7 +383,12 @@ public class OpenFlowDeviceProviderTest {
}
@Override
public void returnRoleReply(RoleState requested, RoleState reponse) {
public void returnRoleReply(RoleState requested, RoleState response) {
}
@Override
public String channelId() {
return "1.2.3.4:1";
}
}
......
......@@ -490,5 +490,11 @@ public class OpenFlowLinkProviderTest {
public void returnRoleReply(RoleState requested, RoleState reponse) {
}
@Override
public String channelId() {
return "1.2.3.4:1";
}
}
}
......
......@@ -423,6 +423,11 @@ public class OpenFlowPacketProviderTest {
public void returnRoleReply(RoleState requested, RoleState reponse) {
}
@Override
public String channelId() {
return "1.2.3.4:1";
}
}
}
......