diff --git a/src/main/java/net/floodlightcontroller/core/web/serializers/IPv4Serializer.java b/src/main/java/net/floodlightcontroller/core/web/serializers/IPv4Serializer.java index db93b66ac46af312c37f59c36febe4357389e188..4d8d4d9b1955b137be2990ab7166284a5854d41e 100644 --- a/src/main/java/net/floodlightcontroller/core/web/serializers/IPv4Serializer.java +++ b/src/main/java/net/floodlightcontroller/core/web/serializers/IPv4Serializer.java @@ -25,17 +25,17 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; - +import org.projectfloodlight.openflow.types.IPv4Address; /** - * Serialize an integer as an IPv4 Address in dotted decimal format + * Serialize an IPv4Address in dotted decimal format */ -public class IPv4Serializer extends JsonSerializer<Integer> { +public class IPv4Serializer extends JsonSerializer<IPv4Address> { @Override - public void serialize(Integer i, JsonGenerator jGen, + public void serialize(IPv4Address ipv4, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException { - jGen.writeString(IPv4.fromIPv4Address(i)); + jGen.writeString(ipv4.toString()); } } diff --git a/src/main/java/net/floodlightcontroller/core/web/serializers/MACSerializer.java b/src/main/java/net/floodlightcontroller/core/web/serializers/MACSerializer.java index c7ea09b8364fa9b6e740da82b2a3f55ec6458fb8..c8a85c4755d68577120e720b03e0d1472f2b712b 100644 --- a/src/main/java/net/floodlightcontroller/core/web/serializers/MACSerializer.java +++ b/src/main/java/net/floodlightcontroller/core/web/serializers/MACSerializer.java @@ -24,17 +24,17 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import org.projectfloodlight.openflow.util.HexString; - +import org.projectfloodlight.openflow.types.MacAddress; /** * Serialize a MAC as colon-separated hexadecimal */ -public class MACSerializer extends JsonSerializer<Long> { +public class MACSerializer extends JsonSerializer<MacAddress> { @Override - public void serialize(Long dpid, JsonGenerator jGen, + public void serialize(MacAddress mac, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException { - jGen.writeString(HexString.toHexString(dpid, 6)); + jGen.writeString(mac.toString()); } } diff --git a/src/main/java/net/floodlightcontroller/core/web/serializers/OFPortSerializer.java b/src/main/java/net/floodlightcontroller/core/web/serializers/OFPortSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..704227412161823e0e246eb24b75d706ecc46439 --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/web/serializers/OFPortSerializer.java @@ -0,0 +1,40 @@ +/** +* Copyright 2011,2012 Big Switch Networks, Inc. +* Originally created by David Erickson, Stanford University +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. You may obtain +* a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations +* under the License. +**/ + +package net.floodlightcontroller.core.web.serializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import org.projectfloodlight.openflow.util.HexString; +import org.projectfloodlight.openflow.types.OFPort; +/** + * Serialize a OFPort as short number + */ +public class OFPortSerializer extends JsonSerializer<OFPort> { + + @Override + public void serialize(OFPort port, JsonGenerator jGen, + SerializerProvider serializer) + throws IOException, JsonProcessingException { + jGen.writeNumber(port.getPortNumber()); + } + +} diff --git a/src/main/java/net/floodlightcontroller/core/web/serializers/VlanVidSerializer.java b/src/main/java/net/floodlightcontroller/core/web/serializers/VlanVidSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..859e76e6c814d5534e81d1eb221ede1882053bde --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/web/serializers/VlanVidSerializer.java @@ -0,0 +1,40 @@ +/** +* Copyright 2011,2012 Big Switch Networks, Inc. +* Originally created by David Erickson, Stanford University +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. You may obtain +* a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations +* under the License. +**/ + +package net.floodlightcontroller.core.web.serializers; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import org.projectfloodlight.openflow.util.HexString; +import org.projectfloodlight.openflow.types.VlanVid; +/** + * Serialize a VlanVid as short number + */ +public class VlanVidSerializer extends JsonSerializer<VlanVid> { + + @Override + public void serialize(VlanVid vlan, JsonGenerator jGen, + SerializerProvider serializer) + throws IOException, JsonProcessingException { + jGen.writeString(vlan.toString()); + } + +} diff --git a/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java b/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java index d057f9c4a353f0501631f6cf7725fd00d4be5b4e..8648e890114da81756013e8094be37444f9a9caf 100644 --- a/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java @@ -21,6 +21,7 @@ import org.projectfloodlight.openflow.types.DatapathId; import org.projectfloodlight.openflow.types.OFPort; import net.floodlightcontroller.core.web.serializers.DPIDSerializer; +import net.floodlightcontroller.core.web.serializers.OFPortSerializer; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -94,6 +95,7 @@ public class SwitchPort { return switchDPID; } + @JsonSerialize(using=OFPortSerializer.class) public OFPort getPort() { return port; } @@ -137,4 +139,4 @@ public class SwitchPort { ", port=" + port + ", errorStatus=" + errorStatus + "]"; } -} \ No newline at end of file +} diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/Entity.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/Entity.java index eda51cc1d45e5d1f713bb9a301d770a962ad2fdc..2dacf2bea58d07991bd9badb4e1ed514cc554bae 100644 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/Entity.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/Entity.java @@ -22,6 +22,8 @@ import java.util.Date; import net.floodlightcontroller.core.web.serializers.IPv4Serializer; import net.floodlightcontroller.core.web.serializers.MACSerializer; import net.floodlightcontroller.core.web.serializers.DPIDSerializer; +import net.floodlightcontroller.core.web.serializers.OFPortSerializer; +import net.floodlightcontroller.core.web.serializers.VlanVidSerializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -138,6 +140,7 @@ public class Entity implements Comparable<Entity> { return ipv4Address; } + @JsonSerialize(using=VlanVidSerializer.class) public VlanVid getVlan() { return vlan; } @@ -147,6 +150,7 @@ public class Entity implements Comparable<Entity> { return switchDPID; } + @JsonSerialize(using=OFPortSerializer.class) public OFPort getSwitchPort() { return switchPort; } @@ -226,45 +230,45 @@ public class Entity implements Comparable<Entity> { StringBuilder builder = new StringBuilder(); builder.append("Entity [macAddress="); if (macAddress != null) { - builder.append(macAddress.toString()); + builder.append(macAddress.toString()); } else { - builder.append("null"); + builder.append("null"); } builder.append(", ipv4Address="); if (ipv4Address != null) { - builder.append(ipv4Address.toString()); + builder.append(ipv4Address.toString()); } else { - builder.append("null"); + builder.append("null"); } builder.append(", vlan="); if (vlan != null) { - builder.append(vlan.getVlan()); + builder.append(vlan.getVlan()); } else { - builder.append("null"); + builder.append("null"); } builder.append(", switchDPID="); if (switchDPID != null) { - builder.append(switchDPID.toString()); + builder.append(switchDPID.toString()); } else { - builder.append("null"); + builder.append("null"); } builder.append(", switchPort="); if (switchPort != null) { - builder.append(switchPort.getPortNumber()); + builder.append(switchPort.getPortNumber()); } else { - builder.append("null"); + builder.append("null"); } builder.append(", lastSeenTimestamp="); if (lastSeenTimestamp != null) { - builder.append(lastSeenTimestamp == null? "null" : lastSeenTimestamp.getTime()); + builder.append(lastSeenTimestamp == null? "null" : lastSeenTimestamp.getTime()); } else { - builder.append("null"); + builder.append("null"); } builder.append(", activeSince="); if (activeSince != null) { - builder.append(activeSince == null? "null" : activeSince.getTime()); + builder.append(activeSince == null? "null" : activeSince.getTime()); } else { - builder.append("null"); + builder.append("null"); } builder.append("]"); return builder.toString(); diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java index 57d27231d07e02d3fb16688599eba9fe94b354db..cf2183a2e8d1f016a68496a4e9cffc38e5dec064 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java @@ -1,4 +1,4 @@ -/** +/**:: * Copyright 2013, Big Switch Networks, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -315,7 +315,7 @@ public class TopologyInstance { Set<Link> lset = switchPortLinks.get(new NodePortTuple(currSw, p)); if (lset == null) continue; for(Link l:lset) { - DatapathId dstSw = l.getDst(); + DatapathId dstSw = l.getDst(); // ignore incoming links. if (dstSw.equals(currSw)) continue; @@ -507,7 +507,7 @@ public class TopologyInstance { seen.put(cnode, true); for (Link link: c.links.get(cnode)) { - DatapathId neighbor; + DatapathId neighbor; if (isDstRooted == true) neighbor = link.getSrc(); else neighbor = link.getDst(); @@ -619,7 +619,7 @@ public class TopologyInstance { // if srcId equals dstId --- and that too is an 'empty' path [] } else if ((nexthoplinks!=null) && (nexthoplinks.get(srcId) != null)) { - while (srcId != dstId) { + while (!srcId.equals(dstId)) { Link l = nexthoplinks.get(srcId); npt = new NodePortTuple(l.getSrc(), l.getSrcPort()); @@ -665,7 +665,7 @@ public class TopologyInstance { } protected Route getRoute(ServiceChain sc, DatapathId srcId, OFPort srcPort, - DatapathId dstId, OFPort dstPort, U64 cookie) { + DatapathId dstId, OFPort dstPort, U64 cookie) { // Return null the route source and desitnation are the @@ -773,7 +773,7 @@ public class TopologyInstance { protected boolean isIncomingBroadcastAllowedOnSwitchPort(DatapathId sw, OFPort portId) { if (isInternalToOpenflowDomain(sw, portId)) { - DatapathId clusterId = getOpenflowDomainId(sw); + DatapathId clusterId = getOpenflowDomainId(sw); NodePortTuple npt = new NodePortTuple(sw, portId); if (clusterBroadcastNodePorts.get(clusterId).contains(npt)) return true; @@ -790,7 +790,7 @@ public class TopologyInstance { protected Set<NodePortTuple> getBroadcastNodePortsInCluster(DatapathId sw) { - DatapathId clusterId = getOpenflowDomainId(sw); + DatapathId clusterId = getOpenflowDomainId(sw); return clusterBroadcastNodePorts.get(clusterId); } @@ -803,13 +803,13 @@ public class TopologyInstance { } public NodePortTuple getOutgoingSwitchPort(DatapathId src, OFPort srcPort, - DatapathId dst, OFPort dstPort) { + DatapathId dst, OFPort dstPort) { // Use this function to redirect traffic if needed. return new NodePortTuple(dst, dstPort); } public NodePortTuple getIncomingSwitchPort(DatapathId src, OFPort srcPort, - DatapathId dst, OFPort dstPort) { + DatapathId dst, OFPort dstPort) { // Use this function to reinject traffic from a // different port if needed. return new NodePortTuple(src, srcPort);