HIGUCHI Yuta | a56fbde | 2013-06-17 14:26:05 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.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 | 9847842 | 2013-09-10 13:53:26 -0700 | [diff] [blame] | 6 | import org.codehaus.jackson.map.ser.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 | |
| 11 | @JsonSerialize(using=ToStringSerializer.class) |
| 12 | public enum UpdateOperation { |
HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -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"); |
| 20 | |
| 21 | private String value; |
| 22 | UpdateOperation(String v) { |
| 23 | value = v; |
| 24 | } |
| 25 | |
| 26 | @Override |
| 27 | public String toString() { |
| 28 | return value; |
| 29 | } |
| 30 | } |
| 31 | |
Pankaj Berde | dc73bb1 | 2013-08-14 13:46:38 -0700 | [diff] [blame] | 32 | public class LDUpdate implements IUpdate{ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | protected long src; |
| 34 | protected short srcPort; |
| 35 | protected long dst; |
| 36 | protected short dstPort; |
| 37 | protected SwitchType srcType; |
| 38 | protected LinkType type; |
| 39 | protected UpdateOperation operation; |
| 40 | |
| 41 | public LDUpdate(long src, short srcPort, |
| 42 | long dst, short dstPort, |
| 43 | ILinkDiscovery.LinkType type, |
| 44 | UpdateOperation operation) { |
| 45 | this.src = src; |
| 46 | this.srcPort = srcPort; |
| 47 | this.dst = dst; |
| 48 | this.dstPort = dstPort; |
| 49 | this.type = type; |
| 50 | this.operation = operation; |
| 51 | } |
| 52 | |
| 53 | public LDUpdate(LDUpdate old) { |
| 54 | this.src = old.src; |
| 55 | this.srcPort = old.srcPort; |
| 56 | this.dst = old.dst; |
| 57 | this.dstPort = old.dstPort; |
| 58 | this.srcType = old.srcType; |
| 59 | this.type = old.type; |
| 60 | this.operation = old.operation; |
| 61 | } |
| 62 | |
| 63 | // For updtedSwitch(sw) |
| 64 | public LDUpdate(long switchId, SwitchType stype, UpdateOperation oper ){ |
| 65 | this.operation = oper; |
| 66 | this.src = switchId; |
| 67 | this.srcType = stype; |
| 68 | } |
| 69 | |
| 70 | // For port up or port down. |
| 71 | public LDUpdate(long sw, short port, UpdateOperation operation) { |
| 72 | this.src = sw; |
| 73 | this.srcPort = port; |
| 74 | this.operation = operation; |
| 75 | } |
| 76 | |
| 77 | public long getSrc() { |
| 78 | return src; |
| 79 | } |
| 80 | |
| 81 | public short getSrcPort() { |
| 82 | return srcPort; |
| 83 | } |
| 84 | |
| 85 | public long getDst() { |
| 86 | return dst; |
| 87 | } |
| 88 | |
| 89 | public short getDstPort() { |
| 90 | return dstPort; |
| 91 | } |
| 92 | |
| 93 | public SwitchType getSrcType() { |
| 94 | return srcType; |
| 95 | } |
| 96 | |
| 97 | public LinkType getType() { |
| 98 | return type; |
| 99 | } |
| 100 | |
| 101 | public UpdateOperation getOperation() { |
| 102 | return operation; |
| 103 | } |
| 104 | |
| 105 | public void setOperation(UpdateOperation operation) { |
| 106 | this.operation = operation; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public String toString() { |
| 111 | switch (operation) { |
HIGUCHI Yuta | 0c3b2ba | 2013-06-17 13:14:41 -0700 | [diff] [blame] | 112 | case LINK_ADDED: |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 113 | case LINK_REMOVED: |
| 114 | case LINK_UPDATED: |
| 115 | return "LDUpdate [operation=" + operation + |
| 116 | ", src=" + HexString.toHexString(src) |
| 117 | + ", srcPort=" + srcPort |
| 118 | + ", dst=" + HexString.toHexString(dst) |
| 119 | + ", dstPort=" + dstPort |
| 120 | + ", type=" + type + "]"; |
| 121 | case PORT_DOWN: |
| 122 | case PORT_UP: |
| 123 | return "LDUpdate [operation=" + operation + |
| 124 | ", src=" + HexString.toHexString(src) |
| 125 | + ", srcPort=" + srcPort + "]"; |
| 126 | case SWITCH_REMOVED: |
| 127 | case SWITCH_UPDATED: |
| 128 | return "LDUpdate [operation=" + operation + |
| 129 | ", src=" + HexString.toHexString(src) + "]"; |
| 130 | default: |
| 131 | return "LDUpdate: Unknown update."; |
| 132 | } |
| 133 | } |
Pankaj Berde | dc73bb1 | 2013-08-14 13:46:38 -0700 | [diff] [blame] | 134 | |
| 135 | @Override |
| 136 | public void dispatch() { |
| 137 | // TODO Auto-generated method stub |
| 138 | |
| 139 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | public enum SwitchType { |
| 143 | BASIC_SWITCH, CORE_SWITCH |
| 144 | }; |
| 145 | |
| 146 | public enum LinkType { |
| 147 | INVALID_LINK { |
| 148 | @Override |
| 149 | public String toString() { |
| 150 | return "invalid"; |
| 151 | } |
| 152 | }, |
| 153 | DIRECT_LINK{ |
| 154 | @Override |
| 155 | public String toString() { |
| 156 | return "internal"; |
| 157 | } |
| 158 | }, |
| 159 | MULTIHOP_LINK { |
| 160 | @Override |
| 161 | public String toString() { |
| 162 | return "external"; |
| 163 | } |
| 164 | }, |
| 165 | TUNNEL { |
| 166 | @Override |
| 167 | public String toString() { |
| 168 | return "tunnel"; |
| 169 | } |
| 170 | } |
| 171 | }; |
| 172 | } |