blob: 6113ea8e6c0a661ba30c3d20f1b0480e673c1aa1 [file] [log] [blame]
HIGUCHI Yutaa56fbde2013-06-17 14:26:05 -07001package net.onrc.onos.ofcontroller.linkdiscovery;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08002
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) {
HIGUCHI Yuta0c3b2ba2013-06-17 13:14:41 -0700110 case LINK_ADDED:
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800111 case LINK_REMOVED:
112 case LINK_UPDATED:
113 return "LDUpdate [operation=" + operation +
114 ", src=" + HexString.toHexString(src)
115 + ", srcPort=" + srcPort
116 + ", dst=" + HexString.toHexString(dst)
117 + ", dstPort=" + dstPort
118 + ", type=" + type + "]";
119 case PORT_DOWN:
120 case PORT_UP:
121 return "LDUpdate [operation=" + operation +
122 ", src=" + HexString.toHexString(src)
123 + ", srcPort=" + srcPort + "]";
124 case SWITCH_REMOVED:
125 case SWITCH_UPDATED:
126 return "LDUpdate [operation=" + operation +
127 ", src=" + HexString.toHexString(src) + "]";
128 default:
129 return "LDUpdate: Unknown update.";
130 }
131 }
132 }
133
134 public enum SwitchType {
135 BASIC_SWITCH, CORE_SWITCH
136 };
137
138 public enum LinkType {
139 INVALID_LINK {
140 @Override
141 public String toString() {
142 return "invalid";
143 }
144 },
145 DIRECT_LINK{
146 @Override
147 public String toString() {
148 return "internal";
149 }
150 },
151 MULTIHOP_LINK {
152 @Override
153 public String toString() {
154 return "external";
155 }
156 },
157 TUNNEL {
158 @Override
159 public String toString() {
160 return "tunnel";
161 }
162 }
163 };
164}