ONOS-535 - capture and display ip address and port of switches
Change-Id: I1671113b35853e258986568cec3a385c281e1147
Showing
7 changed files
with
54 additions
and
2 deletions
| ... | @@ -142,4 +142,9 @@ public interface OpenFlowSwitch { | ... | @@ -142,4 +142,9 @@ public interface OpenFlowSwitch { |
| 142 | */ | 142 | */ |
| 143 | public boolean isOptical(); | 143 | public boolean isOptical(); |
| 144 | 144 | ||
| 145 | + /** | ||
| 146 | + * Identifies the channel used to communicate with the switch. | ||
| 147 | + */ | ||
| 148 | + public String channelId(); | ||
| 149 | + | ||
| 145 | } | 150 | } | ... | ... |
| ... | @@ -17,11 +17,15 @@ | ... | @@ -17,11 +17,15 @@ |
| 17 | package org.onosproject.openflow.controller.driver; | 17 | package org.onosproject.openflow.controller.driver; |
| 18 | 18 | ||
| 19 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | +import java.net.InetSocketAddress; | ||
| 21 | +import java.net.SocketAddress; | ||
| 20 | import java.util.Collections; | 22 | import java.util.Collections; |
| 21 | import java.util.List; | 23 | import java.util.List; |
| 22 | import java.util.concurrent.atomic.AtomicInteger; | 24 | import java.util.concurrent.atomic.AtomicInteger; |
| 23 | 25 | ||
| 24 | import org.jboss.netty.channel.Channel; | 26 | import org.jboss.netty.channel.Channel; |
| 27 | +import org.onlab.packet.Ip4Address; | ||
| 28 | +import org.onlab.packet.IpAddress; | ||
| 25 | import org.onosproject.openflow.controller.Dpid; | 29 | import org.onosproject.openflow.controller.Dpid; |
| 26 | import org.onosproject.openflow.controller.RoleState; | 30 | import org.onosproject.openflow.controller.RoleState; |
| 27 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; | 31 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| ... | @@ -48,6 +52,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { | ... | @@ -48,6 +52,7 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { |
| 48 | protected final Logger log = LoggerFactory.getLogger(getClass()); | 52 | protected final Logger log = LoggerFactory.getLogger(getClass()); |
| 49 | 53 | ||
| 50 | protected Channel channel; | 54 | protected Channel channel; |
| 55 | + protected String channelId; | ||
| 51 | 56 | ||
| 52 | private boolean connected; | 57 | private boolean connected; |
| 53 | protected boolean startDriverHandshakeCalled = false; | 58 | protected boolean startDriverHandshakeCalled = false; |
| ... | @@ -123,8 +128,24 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { | ... | @@ -123,8 +128,24 @@ public abstract class AbstractOpenFlowSwitch implements OpenFlowSwitchDriver { |
| 123 | @Override | 128 | @Override |
| 124 | public final void setChannel(Channel channel) { | 129 | public final void setChannel(Channel channel) { |
| 125 | this.channel = channel; | 130 | this.channel = channel; |
| 131 | + final SocketAddress address = channel.getRemoteAddress(); | ||
| 132 | + if (address instanceof InetSocketAddress) { | ||
| 133 | + final InetSocketAddress inetAddress = (InetSocketAddress) address; | ||
| 134 | + final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); | ||
| 135 | + if (ipAddress.version() == Ip4Address.VERSION) { | ||
| 136 | + channelId = ipAddress.toString() + ':' + inetAddress.getPort(); | ||
| 137 | + } else { | ||
| 138 | + channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); | ||
| 139 | + } | ||
| 140 | + } | ||
| 126 | }; | 141 | }; |
| 127 | 142 | ||
| 143 | + @Override | ||
| 144 | + public String channelId() { | ||
| 145 | + return channelId; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + | ||
| 128 | //************************ | 149 | //************************ |
| 129 | // Switch features related | 150 | // Switch features related |
| 130 | //************************ | 151 | //************************ | ... | ... |
| ... | @@ -300,5 +300,11 @@ public class RoleManagerTest { | ... | @@ -300,5 +300,11 @@ public class RoleManagerTest { |
| 300 | failed = requested; | 300 | failed = requested; |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | + @Override | ||
| 304 | + public String channelId() { | ||
| 305 | + return "1.2.3.4:1"; | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + | ||
| 303 | } | 309 | } |
| 304 | } | 310 | } | ... | ... |
| ... | @@ -186,8 +186,12 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -186,8 +186,12 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
| 186 | Device.Type deviceType = sw.isOptical() ? Device.Type.ROADM : | 186 | Device.Type deviceType = sw.isOptical() ? Device.Type.ROADM : |
| 187 | Device.Type.SWITCH; | 187 | Device.Type.SWITCH; |
| 188 | ChassisId cId = new ChassisId(dpid.value()); | 188 | ChassisId cId = new ChassisId(dpid.value()); |
| 189 | + | ||
| 189 | SparseAnnotations annotations = DefaultAnnotations.builder() | 190 | SparseAnnotations annotations = DefaultAnnotations.builder() |
| 190 | - .set("protocol", sw.factory().getVersion().toString()).build(); | 191 | + .set("protocol", sw.factory().getVersion().toString()) |
| 192 | + .set("channelId", sw.channelId()) | ||
| 193 | + .build(); | ||
| 194 | + | ||
| 191 | DeviceDescription description = | 195 | DeviceDescription description = |
| 192 | new DefaultDeviceDescription(did.uri(), deviceType, | 196 | new DefaultDeviceDescription(did.uri(), deviceType, |
| 193 | sw.manufacturerDescription(), | 197 | sw.manufacturerDescription(), | ... | ... |
| ... | @@ -383,7 +383,12 @@ public class OpenFlowDeviceProviderTest { | ... | @@ -383,7 +383,12 @@ public class OpenFlowDeviceProviderTest { |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | @Override | 385 | @Override |
| 386 | - public void returnRoleReply(RoleState requested, RoleState reponse) { | 386 | + public void returnRoleReply(RoleState requested, RoleState response) { |
| 387 | + } | ||
| 388 | + | ||
| 389 | + @Override | ||
| 390 | + public String channelId() { | ||
| 391 | + return "1.2.3.4:1"; | ||
| 387 | } | 392 | } |
| 388 | 393 | ||
| 389 | } | 394 | } | ... | ... |
| ... | @@ -490,5 +490,11 @@ public class OpenFlowLinkProviderTest { | ... | @@ -490,5 +490,11 @@ public class OpenFlowLinkProviderTest { |
| 490 | public void returnRoleReply(RoleState requested, RoleState reponse) { | 490 | public void returnRoleReply(RoleState requested, RoleState reponse) { |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | + @Override | ||
| 494 | + public String channelId() { | ||
| 495 | + return "1.2.3.4:1"; | ||
| 496 | + } | ||
| 497 | + | ||
| 498 | + | ||
| 493 | } | 499 | } |
| 494 | } | 500 | } | ... | ... |
| ... | @@ -423,6 +423,11 @@ public class OpenFlowPacketProviderTest { | ... | @@ -423,6 +423,11 @@ public class OpenFlowPacketProviderTest { |
| 423 | public void returnRoleReply(RoleState requested, RoleState reponse) { | 423 | public void returnRoleReply(RoleState requested, RoleState reponse) { |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | + @Override | ||
| 427 | + public String channelId() { | ||
| 428 | + return "1.2.3.4:1"; | ||
| 429 | + } | ||
| 430 | + | ||
| 426 | } | 431 | } |
| 427 | 432 | ||
| 428 | } | 433 | } | ... | ... |
-
Please register or login to post a comment