Updated and refactored the JSON serialization of Topology-related
and "Low Intent" objects:
* Added JSON serialization for topology-related FooEvent objects
For now, their format matches exactly the corresponding Topology Foo object:
- DeviceEvent: matches Device
- SwitchEvent: matches Switch
- PortEvent: matches Port
- LinkEvent: matches Link
* Refactored the JSON serialization of existing objects so it
is more consistent:
============================================
- Topology Device serialization: "port" is renamed to "portNumber"
OLD:
{
"mac": "00:01:02:03:04:05"
"attachmentPoints": [
{
"dpid": "11:22:33:44:55:66:77:88",
"port": 1
},
...
]
}
NEW:
{
"mac": "00:01:02:03:04:05"
"attachmentPoints": [
{
"dpid": "11:22:33:44:55:66:77:88",
"portNumber": 1
},
...
]
}
============================================
- Low Level Intent serialization (LinkEvent used by "path"):
portNumber is an integer instead of a string
OLD:
[
...
"path": [
{
"src": {
"portNumber": "2",
"dpid": "00:00:00:00:00:00:02:02"
},
"dst": {
"portNumber": "2",
"dpid": "00:00:00:00:00:00:02:01"
}
},
NEW:
[
...
"path": [
{
"src": {
"portNumber": 2,
"dpid": "00:00:00:00:00:00:02:02"
},
"dst": {
"portNumber": 2,
"dpid": "00:00:00:00:00:00:02:01"
}
},
============================================
- Topology Link serialization: Format changed to match LinkEvent (and SwitchPort):
OLD:
{
...
"links": [
{
"dst-switch": "00:00:00:00:00:00:01:03",
"src-switch": "00:00:00:00:00:00:01:06",
"src-port": 3,
"dst-port": 4
},
NEW:
{
...
"links": [
{
"src": {
"portNumber": 3,
"dpid": "00:00:00:00:00:00:01:06"
},
"dst": {
"portNumber": 4,
"dpid": "00:00:00:00:00:00:01:03"
}
},
============================================
- Topology Port serialization: Renamed "number" to "portNumber"
OLD:
{
"switches": [
{
"state": "ACTIVE",
"ports": [
{
"state": "ACTIVE",
"desc": null,
"number": 1,
"dpid": "00:00:00:00:00:00:04:0e"
},
NEW:
{
"switches": [
{
"state": "ACTIVE",
"ports": [
{
"state": "ACTIVE",
"desc": null,
"portNumber": 1,
"dpid": "00:00:00:00:00:00:04:0e"
},
============================================
- SwitchPort serialization (used in number of places referred above):
portNumber is an integer instead of a string
OLD:
{
"portNumber": "2",
"dpid": "00:00:00:00:00:00:02:02"
}
NEW:
{
"portNumber": 2,
"dpid": "00:00:00:00:00:00:02:02"
}
======================
* Added JSON serialization for TopologyEvents. The format is:
{
"addedSwitches": [
{
"state": "ACTIVE",
"ports": [
],
"dpid": "00:00:00:00:00:00:02:07"
},
...
],
"removedSwitches": [
{
"state": "ACTIVE",
"ports": [
],
"dpid": "00:00:00:00:00:00:02:08"
},
...
],
"addedPorts": [
{
"state": "ACTIVE",
"desc": null,
"portNumber": 1,
"dpid": "00:00:00:00:00:00:02:07"
},
...
],
"removedPorts": [
{
"state": "ACTIVE",
"desc": null,
"portNumber": 1,
"dpid": "00:00:00:00:00:00:02:08"
},
...
],
"addedLinks": [
{
"src": {
"portNumber": 10,
"dpid": "00:00:00:00:00:00:04:01"
},
"dst": {
"portNumber": 2,
"dpid": "00:00:00:00:00:00:04:0a"
}
},
...
],
"removedLinks": [
{
"src": {
"portNumber": 5,
"dpid": "00:00:00:00:00:00:05:01"
},
"dst": {
"portNumber": 6,
"dpid": "00:00:00:00:00:00:05:0a"
}
},
...
],
"addedHosts": [
{
"mac": "00:01:02:03:04:05"
"attachmentPoints": [
{
"dpid": "11:22:33:44:55:66:77:88",
"port": 1
},
...
]
},
...
],
"removedHosts": [
{
"mac": "00:01:02:03:08:08"
"attachmentPoints": [
{
"dpid": "11:22:33:44:55:11:11:11",
"port": 1
},
...
]
},
...
]
}
Change-Id: Ib72be653bc03444b888c0417b3f026966a7df3f3
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java b/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java
index 71b7fb5..e553836 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java
@@ -3,6 +3,9 @@
import java.util.Collection;
import java.util.Collections;
+import net.onrc.onos.core.topology.web.serializers.TopologyEventsSerializer;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
/**
* Class for encapsulating multiple topology events.
* <p/>
@@ -25,6 +28,7 @@
* The above ordering guarantees that adding a port for example
* will be processed after the corresponding switch itself is added.
*/
+@JsonSerialize(using = TopologyEventsSerializer.class)
public final class TopologyEvents {
private final long timestamp;
private final Collection<SwitchEvent> addedSwitchEvents;