blob: 5271794a57ec73637d901c34c714c974a7ed3b8a [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.linkdiscovery.web;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08002
3import java.io.IOException;
4
Jonathan Harta99ec672014-04-03 11:30:34 -07005import net.onrc.onos.core.linkdiscovery.ILinkDiscovery.LinkType;
6import net.onrc.onos.core.linkdiscovery.Link;
7
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08008import org.codehaus.jackson.JsonGenerator;
9import org.codehaus.jackson.JsonProcessingException;
10import org.codehaus.jackson.map.JsonSerializer;
11import org.codehaus.jackson.map.SerializerProvider;
12import org.codehaus.jackson.map.annotate.JsonSerialize;
13import org.openflow.util.HexString;
14
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080015/**
16 * This class is both the datastructure and the serializer
17 * for a link with the corresponding type of link.
Ray Milkey269ffb92014-04-03 14:43:30 -070018 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019 * @author alexreimers
20 */
Ray Milkey269ffb92014-04-03 14:43:30 -070021@JsonSerialize(using = LinkWithType.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022public class LinkWithType extends JsonSerializer<LinkWithType> {
23 public long srcSwDpid;
24 public short srcPort;
25 public int srcPortState;
26 public long dstSwDpid;
27 public short dstPort;
28 public int dstPortState;
29 public LinkType type;
30
31 // Do NOT delete this, it's required for the serializer
Ray Milkey269ffb92014-04-03 14:43:30 -070032 public LinkWithType() {
33 }
34
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080035 public LinkWithType(Link link,
36 int srcPortState,
37 int dstPortState,
38 LinkType type) {
39 this.srcSwDpid = link.getSrc();
40 this.srcPort = link.getSrcPort();
41 this.srcPortState = srcPortState;
42 this.dstSwDpid = link.getDst();
43 this.dstPort = link.getDstPort();
44 this.dstPortState = dstPortState;
45 this.type = type;
46 }
47
Ray Milkey269ffb92014-04-03 14:43:30 -070048 @Override
49 public void serialize(LinkWithType lwt, JsonGenerator jgen, SerializerProvider arg2)
50 throws IOException, JsonProcessingException {
51 // You ****MUST*** use lwt for the fields as it's actually a different object.
52 jgen.writeStartObject();
53 jgen.writeStringField("src-switch", HexString.toHexString(lwt.srcSwDpid));
54 jgen.writeNumberField("src-port", lwt.srcPort);
55 jgen.writeNumberField("src-port-state", lwt.srcPortState);
56 jgen.writeStringField("dst-switch", HexString.toHexString(lwt.dstSwDpid));
57 jgen.writeNumberField("dst-port", lwt.dstPort);
58 jgen.writeNumberField("dst-port-state", lwt.dstPortState);
59 jgen.writeStringField("type", lwt.type.toString());
60 jgen.writeEndObject();
61 }
62
63 @Override
64 public Class<LinkWithType> handledType() {
65 return LinkWithType.class;
66 }
Ray Milkey0f913a02014-04-07 20:58:17 -070067}