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