Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 1 | package net.onrc.onos.datastore.topology; |
| 2 | |
| 3 | import java.nio.ByteBuffer; |
| 4 | import java.util.Arrays; |
| 5 | import java.util.Collection; |
| 6 | import java.util.Collections; |
| 7 | import java.util.Map; |
| 8 | import java.util.HashMap; |
| 9 | import java.util.Set; |
| 10 | import java.util.TreeSet; |
| 11 | |
| 12 | import net.onrc.onos.datastore.RCObject; |
| 13 | import net.onrc.onos.datastore.RCTable; |
| 14 | import net.onrc.onos.datastore.utils.ByteArrayComparator; |
| 15 | |
| 16 | import org.slf4j.Logger; |
| 17 | import org.slf4j.LoggerFactory; |
| 18 | |
| 19 | import com.esotericsoftware.kryo.Kryo; |
| 20 | |
| 21 | import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException; |
| 22 | import edu.stanford.ramcloud.JRamCloud.ObjectExistsException; |
| 23 | import edu.stanford.ramcloud.JRamCloud.WrongVersionException; |
| 24 | |
| 25 | /** |
| 26 | * Switch Object in RC. |
| 27 | * |
| 28 | * @note This class will not maintain invariants. e.g. It will NOT automatically |
| 29 | * remove Ports on Switch, when deleting a Switch. |
| 30 | * |
| 31 | */ |
| 32 | public class RCSwitch extends RCObject { |
| 33 | private static final Logger log = LoggerFactory.getLogger(RCSwitch.class); |
| 34 | |
| 35 | private static final ThreadLocal<Kryo> switchKryo = new ThreadLocal<Kryo>() { |
| 36 | @Override |
| 37 | protected Kryo initialValue() { |
| 38 | Kryo kryo = new Kryo(); |
| 39 | kryo.setRegistrationRequired(true); |
| 40 | kryo.setReferences(false); |
| 41 | kryo.register(byte[].class); |
| 42 | kryo.register(byte[][].class); |
| 43 | kryo.register(HashMap.class); |
| 44 | // TODO check if we should explicitly specify EnumSerializer |
| 45 | kryo.register(STATUS.class); |
| 46 | return kryo; |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | public static final String GLOBAL_SWITCH_TABLE_NAME = "G:Switch"; |
| 51 | |
| 52 | // FIXME these should be Enum or some number, not String |
| 53 | private static final String PROP_DPID = "dpid"; |
| 54 | private static final String PROP_STATUS = "status"; |
| 55 | private static final String PROP_PORT_IDS = "port-ids"; |
| 56 | |
| 57 | // must not re-order enum members, ordinal will be sent over wire |
| 58 | public enum STATUS { |
| 59 | INACTIVE, ACTIVE; |
| 60 | } |
| 61 | |
| 62 | private final Long dpid; |
| 63 | private STATUS status; |
| 64 | private TreeSet<byte[]> portIds; |
| 65 | transient private boolean isPortIdsModified; |
| 66 | |
| 67 | public static final int SWITCHID_BYTES = 2 + 8; |
| 68 | |
| 69 | public static byte[] getSwichID(Long dpid) { |
| 70 | if (dpid == null) { |
| 71 | throw new IllegalArgumentException("dpid cannot be null"); |
| 72 | } |
| 73 | return ByteBuffer.allocate(SWITCHID_BYTES).putChar('S').putLong(dpid) |
| 74 | .array(); |
| 75 | } |
| 76 | |
| 77 | public static long getDpidFromKey(byte[] key) { |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 78 | return getDpidFromKey(ByteBuffer.wrap(key)); |
| 79 | } |
| 80 | |
| 81 | public static long getDpidFromKey(ByteBuffer keyBuf) { |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 82 | if (keyBuf.getChar() != 'S') { |
| 83 | throw new IllegalArgumentException("Invalid Switch key"); |
| 84 | } |
| 85 | return keyBuf.getLong(); |
| 86 | } |
| 87 | |
| 88 | // FIXME specify DPID here, or Should caller specify the key it self? |
| 89 | // In other words, should layer above have the control of the ID? |
| 90 | public RCSwitch(Long dpid) { |
| 91 | super(RCTable.getTable(GLOBAL_SWITCH_TABLE_NAME), getSwichID(dpid)); |
| 92 | |
| 93 | this.dpid = dpid; |
| 94 | this.status = STATUS.INACTIVE; |
| 95 | this.portIds = new TreeSet<>(ByteArrayComparator.BYTEARRAY_COMPARATOR); |
| 96 | this.isPortIdsModified = true; |
| 97 | } |
| 98 | |
| 99 | public static RCSwitch createFromKey(byte[] key) { |
| 100 | return new RCSwitch(getDpidFromKey(key)); |
| 101 | } |
| 102 | |
| 103 | public STATUS getStatus() { |
| 104 | return status; |
| 105 | } |
| 106 | |
| 107 | public void setStatus(STATUS status) { |
| 108 | this.status = status; |
| 109 | getObjectMap().put(PROP_STATUS, status); |
| 110 | } |
| 111 | |
| 112 | public Long getDpid() { |
| 113 | return dpid; |
| 114 | } |
| 115 | |
| 116 | public byte[] getId() { |
| 117 | return getKey(); |
| 118 | } |
| 119 | |
| 120 | public void addPortId(byte[] portId) { |
| 121 | // TODO: Should we copy portId, or reference is OK. |
| 122 | isPortIdsModified |= portIds.add(portId); |
| 123 | } |
| 124 | |
| 125 | public void removePortId(byte[] portId) { |
| 126 | isPortIdsModified |= portIds.remove(portId); |
| 127 | } |
| 128 | |
| 129 | public void emptyPortIds() { |
| 130 | portIds.clear(); |
| 131 | this.isPortIdsModified = true; |
| 132 | } |
| 133 | |
| 134 | public void addAllToPortIds(Collection<byte[]> portIds) { |
| 135 | // TODO: Should we copy portId, or reference is OK. |
| 136 | isPortIdsModified |= this.portIds.addAll(portIds); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * |
| 141 | * @return Unmodifiable Set view of all the PortIds; |
| 142 | */ |
| 143 | public Set<byte[]> getAllPortIds() { |
| 144 | return Collections.unmodifiableSet(portIds); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void serializeAndSetValue() { |
| 149 | Map<Object, Object> map = getObjectMap(); |
| 150 | |
| 151 | map.put(PROP_DPID, this.dpid); |
| 152 | if (isPortIdsModified) { |
| 153 | byte[] portIdArray[] = new byte[portIds.size()][]; |
| 154 | map.put(PROP_PORT_IDS, portIds.toArray(portIdArray)); |
| 155 | isPortIdsModified = false; |
| 156 | } |
| 157 | |
| 158 | serializeAndSetValue(switchKryo.get(), map); |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public Map<Object, Object> deserializeObjectFromValue() { |
| 163 | Map<Object, Object> map = deserializeObjectFromValue(switchKryo.get()); |
| 164 | |
| 165 | this.status = (STATUS) map.get(PROP_STATUS); |
| 166 | |
| 167 | if (this.portIds == null) { |
| 168 | this.portIds = new TreeSet<>( |
| 169 | ByteArrayComparator.BYTEARRAY_COMPARATOR); |
| 170 | } |
| 171 | byte[] portIdArray[] = (byte[][]) map.get(PROP_PORT_IDS); |
| 172 | if (portIdArray != null) { |
| 173 | this.portIds.clear(); |
| 174 | this.portIds.addAll(Arrays.asList(portIdArray)); |
| 175 | isPortIdsModified = false; |
| 176 | } else { |
| 177 | // trigger write on next serialize |
| 178 | isPortIdsModified = true; |
| 179 | } |
| 180 | return map; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public String toString() { |
| 185 | // TODO OUTPUT ALL? |
| 186 | return "[RCSwitch 0x" + Long.toHexString(dpid) + " STATUS:" + status |
| 187 | + "]"; |
| 188 | } |
| 189 | |
| 190 | public static void main(String argv[]) { |
| 191 | // create active switch 0x1 with 2 ports |
| 192 | RCSwitch sw = new RCSwitch(0x1L); |
| 193 | sw.setStatus(STATUS.ACTIVE); |
| 194 | sw.addPortId("SW0x0001P001".getBytes()); |
| 195 | sw.addPortId("SW0x0001P002".getBytes()); |
| 196 | |
| 197 | try { |
| 198 | sw.create(); |
| 199 | } catch (ObjectExistsException e) { |
| 200 | log.debug("Create Switch Failed", e); |
| 201 | e.printStackTrace(); |
| 202 | } |
| 203 | |
| 204 | // read switch 0x1 |
| 205 | RCSwitch swRead = new RCSwitch(0x1L); |
| 206 | try { |
| 207 | swRead.read(); |
| 208 | } catch (ObjectDoesntExistException e) { |
| 209 | log.debug("Reading Switch Failed", e); |
| 210 | } |
| 211 | assert (swRead.getStatus() == STATUS.ACTIVE); |
| 212 | for (byte[] portId : swRead.getAllPortIds()) { |
| 213 | // bad example code, portId is not expected to be ASCII string |
| 214 | log.debug("PortId: {}", new String(portId)); |
| 215 | } |
| 216 | assert (swRead.getAllPortIds().size() == 2); |
| 217 | |
| 218 | // update 0x1 |
| 219 | swRead.setStatus(STATUS.INACTIVE); |
| 220 | swRead.removePortId("SW0x0001P001".getBytes()); |
| 221 | try { |
| 222 | swRead.update(); |
| 223 | } catch (ObjectDoesntExistException | WrongVersionException e) { |
| 224 | log.debug("Updating Switch Failed", e); |
| 225 | } |
| 226 | |
| 227 | // read 0x1 again and delete |
| 228 | RCSwitch swRead2 = new RCSwitch(0x1L); |
| 229 | try { |
| 230 | swRead2.read(); |
| 231 | } catch (ObjectDoesntExistException e) { |
| 232 | log.debug("Reading Switch Again Failed", e); |
| 233 | } |
| 234 | assert (swRead2.getStatus() == STATUS.INACTIVE); |
| 235 | for (byte[] portId : swRead2.getAllPortIds()) { |
| 236 | // bad example code, portId is not expected to be ASCII string |
| 237 | log.debug("PortId: {}", new String(portId)); |
| 238 | } |
| 239 | assert (swRead2.getAllPortIds().size() == 1); |
| 240 | try { |
| 241 | swRead2.delete(); |
| 242 | } catch (ObjectDoesntExistException e) { |
| 243 | log.debug("Deleting Switch Failed", e); |
| 244 | } |
| 245 | |
| 246 | RCSwitch swRead3 = new RCSwitch(0x1L); |
| 247 | try { |
| 248 | swRead3.read(); |
| 249 | } catch (ObjectDoesntExistException e) { |
| 250 | log.debug("Switch not found as expected"); |
| 251 | } |
| 252 | |
| 253 | topology_setup(); |
| 254 | topology_walk(); |
| 255 | topology_delete(); |
| 256 | } |
| 257 | |
| 258 | private static void topology_setup() { |
| 259 | log.debug("topology_setup start."); |
| 260 | |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 261 | // d1 - s1p1 - s1 - s1p2 - s2p1 - s2 - s2p2 |
| 262 | |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 263 | RCSwitch sw1 = new RCSwitch(0x1L); |
| 264 | sw1.setStatus(STATUS.ACTIVE); |
| 265 | try { |
| 266 | sw1.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 267 | log.debug("Create {}", sw1); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 268 | } catch (ObjectExistsException e) { |
| 269 | log.error("Switch creation failed", e); |
| 270 | } |
| 271 | |
| 272 | RCPort sw1p1 = new RCPort(0x1L, 1L); |
| 273 | sw1p1.setStatus(RCPort.STATUS.ACTIVE); |
| 274 | RCPort sw1p2 = new RCPort(0x1L, 2L); |
| 275 | sw1p2.setStatus(RCPort.STATUS.ACTIVE); |
| 276 | try { |
| 277 | sw1p1.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 278 | log.debug("Create {}", sw1p1); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 279 | sw1p2.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 280 | log.debug("Create {}", sw1p2); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 281 | } catch (ObjectExistsException e) { |
| 282 | log.error("Port creation failed", e); |
| 283 | } |
| 284 | |
| 285 | sw1.emptyPortIds(); |
| 286 | sw1.addPortId(sw1p1.getId()); |
| 287 | sw1.addPortId(sw1p2.getId()); |
| 288 | try { |
| 289 | sw1.update(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 290 | log.debug("Update {} - {}", sw1, sw1.getAllPortIds()); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 291 | } catch (ObjectDoesntExistException | WrongVersionException e) { |
| 292 | log.error("Switch update failed", e); |
| 293 | } |
| 294 | |
| 295 | RCDevice d1 = new RCDevice(new byte[] { 0, 1, 2, 3, 4, 5, 6 }); |
| 296 | d1.addPortId(sw1p1.getId()); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 297 | sw1p1.addDeviceId(d1.getId()); |
| 298 | |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 299 | try { |
| 300 | d1.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 301 | log.debug("Create {}", d1); |
| 302 | try { |
| 303 | sw1p1.update(); |
| 304 | } catch (ObjectDoesntExistException | WrongVersionException e) { |
| 305 | log.error("Link update failed", e); |
| 306 | } |
| 307 | log.debug("Create {}", sw1p1); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 308 | } catch (ObjectExistsException e) { |
| 309 | log.error("Device creation failed", e); |
| 310 | } |
| 311 | |
| 312 | RCSwitch sw2 = new RCSwitch(0x2L); |
| 313 | sw2.setStatus(STATUS.ACTIVE); |
| 314 | RCPort sw2p1 = new RCPort(0x2L, 1L); |
| 315 | sw2p1.setStatus(RCPort.STATUS.ACTIVE); |
| 316 | RCPort sw2p2 = new RCPort(0x2L, 2L); |
| 317 | sw2p2.setStatus(RCPort.STATUS.ACTIVE); |
| 318 | |
| 319 | sw2.addPortId(sw2p1.getId()); |
| 320 | sw2.addPortId(sw2p2.getId()); |
| 321 | sw2.addAllToPortIds(Arrays.asList(sw2p1.getId(), sw2p2.getId())); |
| 322 | assert (sw2.getAllPortIds().size() == 2); |
| 323 | |
| 324 | RCDevice d2 = new RCDevice(new byte[] { 6, 5, 4, 3, 2, 1, 0 }); |
| 325 | d2.addPortId(sw2p2.getId()); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 326 | sw2p2.addDeviceId(d2.getId()); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 327 | |
| 328 | try { |
| 329 | sw2.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 330 | log.debug("Create {}", sw2); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 331 | sw2p1.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 332 | log.debug("Create {}", sw2p1); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 333 | sw2p2.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 334 | log.debug("Create {}", sw2p2); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 335 | d2.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 336 | log.debug("Create {}", d2); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 337 | } catch (ObjectExistsException e) { |
| 338 | log.error("One of Switch/Port/Device creation failed", e); |
| 339 | } |
| 340 | |
| 341 | RCLink l1 = new RCLink(0x1L, 2L, 0x2L, 1L); |
| 342 | l1.setStatus(RCLink.STATUS.ACTIVE); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 343 | |
| 344 | sw1p2.addLinkId(l1.getId()); |
| 345 | sw2p1.addLinkId(l1.getId()); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 346 | try { |
| 347 | l1.create(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 348 | log.debug("Create {}", l1); |
| 349 | try { |
| 350 | sw1p2.update(); |
| 351 | log.debug("Update {}", sw1p2); |
| 352 | sw2p1.update(); |
| 353 | log.debug("Update {}", sw2p1); |
| 354 | } catch (ObjectDoesntExistException | WrongVersionException e) { |
| 355 | log.error("Port update failed", e); |
| 356 | } |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 357 | } catch (ObjectExistsException e) { |
| 358 | log.error("Link creation failed", e); |
| 359 | } |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 360 | |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 361 | log.debug("topology_setup end."); |
| 362 | } |
| 363 | |
| 364 | private static void topology_walk() { |
| 365 | log.debug("topology_walk start."); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 366 | |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 367 | RCSwitch sw1 = new RCSwitch(0x1L); |
| 368 | try { |
| 369 | sw1.read(); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 370 | log.debug("{}", sw1); |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 371 | } catch (ObjectDoesntExistException e) { |
| 372 | log.error("Reading switch failed", e); |
| 373 | } |
| 374 | |
| 375 | assert (sw1.getDpid() == 0x1L); |
| 376 | assert (sw1.getStatus() == STATUS.ACTIVE); |
| 377 | assert (sw1.getAllPortIds().size() == 2); |
| 378 | for (byte[] portId : sw1.getAllPortIds()) { |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 379 | RCPort port = RCPort.createFromKey(portId); |
| 380 | try { |
| 381 | port.read(); |
| 382 | assert (port.getDpid() == 0x1L); |
| 383 | log.debug("Port 0x1:{} - LinkIDs:{} DeviceIDs:{}", |
| 384 | port.getNumber(), port.getAllLinkIds(), |
| 385 | port.getAllDeviceIds()); |
| 386 | |
| 387 | for (byte[] deviceId : port.getAllDeviceIds()) { |
| 388 | RCDevice device = RCDevice.createFromKey(deviceId); |
| 389 | try { |
| 390 | device.read(); |
| 391 | log.debug("Device {} - PortIDs:{}", device.getMac(), |
| 392 | device.getAllPortIds()); |
| 393 | } catch (ObjectDoesntExistException e) { |
| 394 | log.error("Reading Device failed", e); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | for (byte[] linkId : port.getAllLinkIds()) { |
| 399 | RCLink link = RCLink.createFromKey(linkId); |
| 400 | try { |
| 401 | link.read(); |
| 402 | log.debug("Link {}", link); |
| 403 | } catch (ObjectDoesntExistException e) { |
| 404 | log.error("Reading Link failed", e); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | } catch (ObjectDoesntExistException e) { |
| 409 | log.error("Reading Port failed", e); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | RCSwitch sw2 = new RCSwitch(0x1L); |
| 414 | try { |
| 415 | sw2.read(); |
| 416 | log.debug("{}", sw2); |
| 417 | } catch (ObjectDoesntExistException e) { |
| 418 | log.error("Reading switch failed", e); |
| 419 | } |
| 420 | |
| 421 | assert (sw2.getDpid() == 0x2L); |
| 422 | assert (sw2.getStatus() == STATUS.ACTIVE); |
| 423 | assert (sw2.getAllPortIds().size() == 2); |
| 424 | for (byte[] portId : sw2.getAllPortIds()) { |
| 425 | RCPort port = RCPort.createFromKey(portId); |
| 426 | try { |
| 427 | port.read(); |
| 428 | assert (port.getDpid() == 0x1L); |
| 429 | log.debug("Port 0x2:{} - LinkIDs:{} DeviceIDs:{}", |
| 430 | port.getNumber(), port.getAllLinkIds(), |
| 431 | port.getAllDeviceIds()); |
| 432 | |
| 433 | for (byte[] deviceId : port.getAllDeviceIds()) { |
| 434 | RCDevice device = RCDevice.createFromKey(deviceId); |
| 435 | try { |
| 436 | device.read(); |
| 437 | log.debug("Device {} - PortIDs:{}", device, |
| 438 | device.getAllPortIds()); |
| 439 | } catch (ObjectDoesntExistException e) { |
| 440 | log.error("Reading Device failed", e); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | for (byte[] linkId : port.getAllLinkIds()) { |
| 445 | RCLink link = RCLink.createFromKey(linkId); |
| 446 | try { |
| 447 | link.read(); |
| 448 | log.debug("Link {}", link); |
| 449 | } catch (ObjectDoesntExistException e) { |
| 450 | log.error("Reading Link failed", e); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | } catch (ObjectDoesntExistException e) { |
| 455 | log.error("Reading Port failed", e); |
| 456 | } |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | log.debug("topology_walk end."); |
| 460 | } |
| 461 | |
| 462 | private static void topology_delete() { |
| 463 | log.debug("topology_delete start."); |
Yuta HIGUCHI | c9d06ef | 2014-01-31 15:55:12 -0800 | [diff] [blame^] | 464 | |
| 465 | // TODO implement get all kind of API |
| 466 | RCSwitch sw1 = new RCSwitch(0x1L); |
| 467 | RCPort sw1p1 = new RCPort(0x1L, 1L); |
| 468 | RCPort sw1p2 = new RCPort(0x1L, 2L); |
| 469 | RCDevice d1 = new RCDevice(new byte[] { 0, 1, 2, 3, 4, 5, 6 }); |
| 470 | RCLink l1 = new RCLink(0x1L, 2L, 0x2L, 1L); |
| 471 | RCSwitch sw2 = new RCSwitch(0x2L); |
| 472 | RCPort sw2p1 = new RCPort(0x2L, 1L); |
| 473 | RCPort sw2p2 = new RCPort(0x2L, 2L); |
| 474 | RCDevice d2 = new RCDevice(new byte[] { 6, 5, 4, 3, 2, 1, 0 }); |
| 475 | |
| 476 | try { |
| 477 | sw1.read(); |
| 478 | sw1.delete(); |
| 479 | } catch (ObjectDoesntExistException e) { |
| 480 | log.debug("Delete Switch Failed", e); |
| 481 | } |
| 482 | try { |
| 483 | sw1p1.read(); |
| 484 | sw1p1.delete(); |
| 485 | } catch (ObjectDoesntExistException e) { |
| 486 | log.debug("Delete Port Failed", e); |
| 487 | } |
| 488 | try { |
| 489 | sw1p2.read(); |
| 490 | sw1p2.delete(); |
| 491 | } catch (ObjectDoesntExistException e) { |
| 492 | log.debug("Delete Port Failed", e); |
| 493 | } |
| 494 | try { |
| 495 | d1.read(); |
| 496 | d1.delete(); |
| 497 | } catch (ObjectDoesntExistException e) { |
| 498 | log.debug("Delete Device Failed", e); |
| 499 | } |
| 500 | |
| 501 | try { |
| 502 | l1.read(); |
| 503 | l1.delete(); |
| 504 | } catch (ObjectDoesntExistException e) { |
| 505 | log.debug("Delete Link Failed", e); |
| 506 | } |
| 507 | |
| 508 | try { |
| 509 | sw2.read(); |
| 510 | sw2.delete(); |
| 511 | } catch (ObjectDoesntExistException e) { |
| 512 | log.debug("Delete Switch Failed", e); |
| 513 | } |
| 514 | try { |
| 515 | sw2p1.read(); |
| 516 | sw2p1.delete(); |
| 517 | } catch (ObjectDoesntExistException e) { |
| 518 | log.debug("Delete Port Failed", e); |
| 519 | } |
| 520 | try { |
| 521 | sw2p2.read(); |
| 522 | sw2p2.delete(); |
| 523 | } catch (ObjectDoesntExistException e) { |
| 524 | log.debug("Delete Port Failed", e); |
| 525 | } |
| 526 | try { |
| 527 | d2.read(); |
| 528 | d2.delete(); |
| 529 | } catch (ObjectDoesntExistException e) { |
| 530 | log.debug("Delete Device Failed", e); |
| 531 | } |
| 532 | |
Yuta HIGUCHI | 1ef85c4 | 2014-01-29 17:23:21 -0800 | [diff] [blame] | 533 | log.debug("topology_delete end."); |
| 534 | } |
| 535 | |
| 536 | } |