Added ip info for CLI (show host)
diff --git a/cli/cli/rest_to_model.py b/cli/cli/rest_to_model.py
index 34506ce..7ef25a9 100755
--- a/cli/cli/rest_to_model.py
+++ b/cli/cli/rest_to_model.py
@@ -196,18 +196,16 @@
lastseen = 0
ips = None
- if onos == 0:
- if not ip_match and not ip_prefix:
- ipv4 = entry['ipv4']
- elif ip_match:
- ipv4 = [x for x in entry['ipv4'] if x == ip_match]
- elif ip_prefix:
- ipv4 = [x for x in entry['ipv4'] if x.startswith(ip_prefix)]
+ if not ip_match and not ip_prefix:
+ ipv4 = entry['ipv4']
+ elif ip_match:
+ ipv4 = [x for x in entry['ipv4'] if x == ip_match]
+ elif ip_prefix:
+ ipv4 = [x for x in entry['ipv4'] if x.startswith(ip_prefix)]
- if len(entry['ipv4']):
- ips = [{'ip-address' : x, 'last-seen' : lastseen}
- for x in entry['ipv4'] ]
-
+ if len(entry['ipv4']):
+ ips = [{'ip-address' : entry['ipv4'], 'last-seen' : lastseen}]
+ #for x in entry['ipv4'] ]
aps = None
switch = []
port = []
@@ -257,7 +255,7 @@
result.append({'id' : id,
'mac' : mac,
'ips' : ips,
- 'ipv4' : 0,
+ 'ipv4' : ipv4,
'attachment-points' : aps,
'dpid' : switch,
'port' : port,
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java b/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
index b591044..4f20a81 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyPublisher.java
@@ -395,7 +395,6 @@
ConfigState.NOT_CONFIGURED.toString());
}
switchData.freeze();
- System.out.println("getOnosInstanceId().toString():\n\n\n\n\n"+getOnosInstanceId());
// The Port events
List<PortData> portDataEntries = new ArrayList<PortData>();
for (OFPortDesc port : sw.getPorts()) {
diff --git a/src/main/java/net/onrc/onos/core/topology/web/serializers/HostDataSerializer.java b/src/main/java/net/onrc/onos/core/topology/web/serializers/HostDataSerializer.java
index 7099c83..86d92dc 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/serializers/HostDataSerializer.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/serializers/HostDataSerializer.java
@@ -44,6 +44,7 @@
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(TopologyElement.TYPE, hostData.getType());
jsonGenerator.writeStringField("mac", hostData.getMac().toString());
+ jsonGenerator.writeStringField("ipv4", IPAddressToString(hostData.getIp()));
jsonGenerator.writeFieldName("attachmentPoints");
jsonGenerator.writeStartArray();
for (SwitchPort switchPort : hostData.getAttachmentPoints()) {
@@ -57,4 +58,10 @@
jsonGenerator.writeEndObject(); // stringAttributes
jsonGenerator.writeEndObject();
}
+ public String IPAddressToString(int ip) {
+ return ((ip >> 24) & 0xFF) + "." +
+ ((ip >> 16) & 0xFF) + "." +
+ ((ip >> 8) & 0xFF) + "." +
+ (ip & 0xFF);
+ }
}
diff --git a/src/main/java/net/onrc/onos/core/topology/web/serializers/HostSerializer.java b/src/main/java/net/onrc/onos/core/topology/web/serializers/HostSerializer.java
index b0f7824..d03c820 100644
--- a/src/main/java/net/onrc/onos/core/topology/web/serializers/HostSerializer.java
+++ b/src/main/java/net/onrc/onos/core/topology/web/serializers/HostSerializer.java
@@ -43,6 +43,7 @@
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(TopologyElement.TYPE, host.getType());
jsonGenerator.writeStringField("mac", host.getMacAddress().toString());
+ jsonGenerator.writeStringField("ipv4", IPAddressToString(host.getIpAddress()));
jsonGenerator.writeFieldName("attachmentPoints");
jsonGenerator.writeStartArray();
for (Port port : host.getAttachmentPoints()) {
@@ -62,4 +63,10 @@
jsonGenerator.writeEndObject(); // stringAttributes
jsonGenerator.writeEndObject();
}
+ public String IPAddressToString(int ip) {
+ return ((ip >> 24) & 0xFF) + "." +
+ ((ip >> 16) & 0xFF) + "." +
+ ((ip >> 8) & 0xFF) + "." +
+ (ip & 0xFF);
+ }
}