Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.linkdiscovery; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 2 | |
Pankaj Berde | dc73bb1 | 2013-08-14 13:46:38 -0700 | [diff] [blame] | 3 | import net.floodlightcontroller.core.IUpdate; |
| 4 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 5 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
Pankaj Berde | 5024ec1 | 2013-01-31 17:07:29 -0800 | [diff] [blame] | 6 | import org.codehaus.jackson.map.ser.std.ToStringSerializer; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 7 | import org.openflow.util.HexString; |
| 8 | |
| 9 | public interface ILinkDiscovery { |
| 10 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 11 | @JsonSerialize(using = ToStringSerializer.class) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 12 | public enum UpdateOperation { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 13 | LINK_ADDED("Link Added"), // Operation Added by ONOS |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 14 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 21 | private String value; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 22 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 23 | UpdateOperation(String v) { |
| 24 | value = v; |
| 25 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 26 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 27 | @Override |
| 28 | public String toString() { |
| 29 | return value; |
| 30 | } |
| 31 | } |
| 32 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 33 | public class LDUpdate implements IUpdate { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 34 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 43 | long dst, short dstPort, |
| 44 | ILinkDiscovery.LinkType type, |
| 45 | UpdateOperation operation) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 46 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 65 | public LDUpdate(long switchId, SwitchType stype, UpdateOperation oper) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 66 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 109 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 110 | @Override |
| 111 | public String toString() { |
| 112 | switch (operation) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 113 | 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 133 | } |
| 134 | } |
Pankaj Berde | dc73bb1 | 2013-08-14 13:46:38 -0700 | [diff] [blame] | 135 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 136 | @Override |
| 137 | public void dispatch() { |
| 138 | // TODO Auto-generated method stub |
| 139 | |
| 140 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | public enum SwitchType { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 144 | BASIC_SWITCH, |
| 145 | CORE_SWITCH |
| 146 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 147 | |
| 148 | public enum LinkType { |
| 149 | INVALID_LINK { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 150 | @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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 161 | MULTIHOP_LINK { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 162 | @Override |
| 163 | public String toString() { |
| 164 | return "external"; |
| 165 | } |
| 166 | }, |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 167 | TUNNEL { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 168 | @Override |
| 169 | public String toString() { |
| 170 | return "tunnel"; |
| 171 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 172 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 173 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 174 | } |