blob: bfc19d2379d0504fb8848d48157123d4e821a988 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.linkdiscovery;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08002
Pankaj Berdedc73bb12013-08-14 13:46:38 -07003import net.floodlightcontroller.core.IUpdate;
4
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08005import org.codehaus.jackson.map.annotate.JsonSerialize;
Pankaj Berde5024ec12013-01-31 17:07:29 -08006import org.codehaus.jackson.map.ser.std.ToStringSerializer;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08007import org.openflow.util.HexString;
8
9public interface ILinkDiscovery {
10
Ray Milkey269ffb92014-04-03 14:43:30 -070011 @JsonSerialize(using = ToStringSerializer.class)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080012 public enum UpdateOperation {
Ray Milkey269ffb92014-04-03 14:43:30 -070013 LINK_ADDED("Link Added"), // Operation Added by ONOS
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080014 LINK_UPDATED("Link Updated"),
15 LINK_REMOVED("Link Removed"),
16 SWITCH_UPDATED("Switch Updated"),
17 SWITCH_REMOVED("Switch Removed"),
18 PORT_UP("Port Up"),
19 PORT_DOWN("Port Down");
Ray Milkey269ffb92014-04-03 14:43:30 -070020
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080021 private String value;
Ray Milkey269ffb92014-04-03 14:43:30 -070022
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080023 UpdateOperation(String v) {
24 value = v;
25 }
Ray Milkey269ffb92014-04-03 14:43:30 -070026
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080027 @Override
28 public String toString() {
29 return value;
30 }
31 }
32
Ray Milkey269ffb92014-04-03 14:43:30 -070033 public class LDUpdate implements IUpdate {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080034 protected long src;
35 protected short srcPort;
36 protected long dst;
37 protected short dstPort;
38 protected SwitchType srcType;
39 protected LinkType type;
40 protected UpdateOperation operation;
41
42 public LDUpdate(long src, short srcPort,
Ray Milkey269ffb92014-04-03 14:43:30 -070043 long dst, short dstPort,
44 ILinkDiscovery.LinkType type,
45 UpdateOperation operation) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046 this.src = src;
47 this.srcPort = srcPort;
48 this.dst = dst;
49 this.dstPort = dstPort;
50 this.type = type;
51 this.operation = operation;
52 }
53
54 public LDUpdate(LDUpdate old) {
55 this.src = old.src;
56 this.srcPort = old.srcPort;
57 this.dst = old.dst;
58 this.dstPort = old.dstPort;
59 this.srcType = old.srcType;
60 this.type = old.type;
61 this.operation = old.operation;
62 }
63
64 // For updtedSwitch(sw)
Ray Milkey269ffb92014-04-03 14:43:30 -070065 public LDUpdate(long switchId, SwitchType stype, UpdateOperation oper) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080066 this.operation = oper;
67 this.src = switchId;
68 this.srcType = stype;
69 }
70
71 // For port up or port down.
72 public LDUpdate(long sw, short port, UpdateOperation operation) {
73 this.src = sw;
74 this.srcPort = port;
75 this.operation = operation;
76 }
77
78 public long getSrc() {
79 return src;
80 }
81
82 public short getSrcPort() {
83 return srcPort;
84 }
85
86 public long getDst() {
87 return dst;
88 }
89
90 public short getDstPort() {
91 return dstPort;
92 }
93
94 public SwitchType getSrcType() {
95 return srcType;
96 }
97
98 public LinkType getType() {
99 return type;
100 }
101
102 public UpdateOperation getOperation() {
103 return operation;
104 }
105
106 public void setOperation(UpdateOperation operation) {
107 this.operation = operation;
108 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700109
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800110 @Override
111 public String toString() {
112 switch (operation) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700113 case LINK_ADDED:
114 case LINK_REMOVED:
115 case LINK_UPDATED:
116 return "LDUpdate [operation=" + operation +
117 ", src=" + HexString.toHexString(src)
118 + ", srcPort=" + srcPort
119 + ", dst=" + HexString.toHexString(dst)
120 + ", dstPort=" + dstPort
121 + ", type=" + type + "]";
122 case PORT_DOWN:
123 case PORT_UP:
124 return "LDUpdate [operation=" + operation +
125 ", src=" + HexString.toHexString(src)
126 + ", srcPort=" + srcPort + "]";
127 case SWITCH_REMOVED:
128 case SWITCH_UPDATED:
129 return "LDUpdate [operation=" + operation +
130 ", src=" + HexString.toHexString(src) + "]";
131 default:
132 return "LDUpdate: Unknown update.";
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800133 }
134 }
Pankaj Berdedc73bb12013-08-14 13:46:38 -0700135
Ray Milkey269ffb92014-04-03 14:43:30 -0700136 @Override
137 public void dispatch() {
138 // TODO Auto-generated method stub
139
140 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800141 }
142
143 public enum SwitchType {
Ray Milkey269ffb92014-04-03 14:43:30 -0700144 BASIC_SWITCH,
145 CORE_SWITCH
146 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800147
148 public enum LinkType {
149 INVALID_LINK {
Ray Milkey269ffb92014-04-03 14:43:30 -0700150 @Override
151 public String toString() {
152 return "invalid";
153 }
154 },
155 DIRECT_LINK {
156 @Override
157 public String toString() {
158 return "internal";
159 }
160 },
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800161 MULTIHOP_LINK {
Ray Milkey269ffb92014-04-03 14:43:30 -0700162 @Override
163 public String toString() {
164 return "external";
165 }
166 },
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800167 TUNNEL {
Ray Milkey269ffb92014-04-03 14:43:30 -0700168 @Override
169 public String toString() {
170 return "tunnel";
171 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800172 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700173 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800174}