blob: 1efe015bdc9a241fa9f1aad7a0fc5e09e072cce7 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.linkdiscovery;
2
3import org.codehaus.jackson.map.annotate.JsonSerialize;
Pankaj Berde5024ec12013-01-31 17:07:29 -08004import org.codehaus.jackson.map.ser.std.ToStringSerializer;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08005import org.openflow.util.HexString;
6
7public interface ILinkDiscovery {
8
9 @JsonSerialize(using=ToStringSerializer.class)
10 public enum UpdateOperation {
11 LINK_UPDATED("Link Updated"),
12 LINK_REMOVED("Link Removed"),
13 SWITCH_UPDATED("Switch Updated"),
14 SWITCH_REMOVED("Switch Removed"),
15 PORT_UP("Port Up"),
16 PORT_DOWN("Port Down");
17
18 private String value;
19 UpdateOperation(String v) {
20 value = v;
21 }
22
23 @Override
24 public String toString() {
25 return value;
26 }
27 }
28
29 public class LDUpdate {
30 protected long src;
31 protected short srcPort;
32 protected long dst;
33 protected short dstPort;
34 protected SwitchType srcType;
35 protected LinkType type;
36 protected UpdateOperation operation;
37
38 public LDUpdate(long src, short srcPort,
39 long dst, short dstPort,
40 ILinkDiscovery.LinkType type,
41 UpdateOperation operation) {
42 this.src = src;
43 this.srcPort = srcPort;
44 this.dst = dst;
45 this.dstPort = dstPort;
46 this.type = type;
47 this.operation = operation;
48 }
49
50 public LDUpdate(LDUpdate old) {
51 this.src = old.src;
52 this.srcPort = old.srcPort;
53 this.dst = old.dst;
54 this.dstPort = old.dstPort;
55 this.srcType = old.srcType;
56 this.type = old.type;
57 this.operation = old.operation;
58 }
59
60 // For updtedSwitch(sw)
61 public LDUpdate(long switchId, SwitchType stype, UpdateOperation oper ){
62 this.operation = oper;
63 this.src = switchId;
64 this.srcType = stype;
65 }
66
67 // For port up or port down.
68 public LDUpdate(long sw, short port, UpdateOperation operation) {
69 this.src = sw;
70 this.srcPort = port;
71 this.operation = operation;
72 }
73
74 public long getSrc() {
75 return src;
76 }
77
78 public short getSrcPort() {
79 return srcPort;
80 }
81
82 public long getDst() {
83 return dst;
84 }
85
86 public short getDstPort() {
87 return dstPort;
88 }
89
90 public SwitchType getSrcType() {
91 return srcType;
92 }
93
94 public LinkType getType() {
95 return type;
96 }
97
98 public UpdateOperation getOperation() {
99 return operation;
100 }
101
102 public void setOperation(UpdateOperation operation) {
103 this.operation = operation;
104 }
105
106 @Override
107 public String toString() {
108 switch (operation) {
109 case LINK_REMOVED:
110 case LINK_UPDATED:
111 return "LDUpdate [operation=" + operation +
112 ", src=" + HexString.toHexString(src)
113 + ", srcPort=" + srcPort
114 + ", dst=" + HexString.toHexString(dst)
115 + ", dstPort=" + dstPort
116 + ", type=" + type + "]";
117 case PORT_DOWN:
118 case PORT_UP:
119 return "LDUpdate [operation=" + operation +
120 ", src=" + HexString.toHexString(src)
121 + ", srcPort=" + srcPort + "]";
122 case SWITCH_REMOVED:
123 case SWITCH_UPDATED:
124 return "LDUpdate [operation=" + operation +
125 ", src=" + HexString.toHexString(src) + "]";
126 default:
127 return "LDUpdate: Unknown update.";
128 }
129 }
130 }
131
132 public enum SwitchType {
133 BASIC_SWITCH, CORE_SWITCH
134 };
135
136 public enum LinkType {
137 INVALID_LINK {
138 @Override
139 public String toString() {
140 return "invalid";
141 }
142 },
143 DIRECT_LINK{
144 @Override
145 public String toString() {
146 return "internal";
147 }
148 },
149 MULTIHOP_LINK {
150 @Override
151 public String toString() {
152 return "external";
153 }
154 },
155 TUNNEL {
156 @Override
157 public String toString() {
158 return "tunnel";
159 }
160 }
161 };
162}