blob: 6809125521f43e46380ee32f57668aa47d01de8d [file] [log] [blame]
Pavlin Radoslavovaaace7f2013-10-25 19:42:00 -07001package net.onrc.onos.ofcontroller.topology;
2
3/**
4 * Class for storing information about a Topology Element: Switch, Port or
5 * Link.
6 */
7public class TopologyElement {
8 /**
9 * The Element Type.
10 */
11 enum Type {
12 ELEMENT_SWITCH, // Network Switch
13 ELEMENT_PORT, // Switch Port
14 ELEMENT_LINK // Unidirectional Link between Switch Ports
15 }
16
17 private Type elementType; // The element type
18 private long fromSwitchDpid = 0; // The Switch DPID
19 private int fromSwitchPort = 0; // The Switch Port
20 private long toSwitchDpid = 0; // The Neighbor Switch DPID
21 private int toSwitchPort = 0; // The Neighbor Switch Port
22
23 /**
24 * Constructor to create a Topology Element for a Switch.
25 *
26 * @param switchDpid the Switch DPID.
27 */
28 public TopologyElement(long switchDpid) {
29 this.elementType = Type.ELEMENT_SWITCH;
30 this.fromSwitchDpid = switchDpid;
31 }
32
33 /**
34 * Constructor to create a Topology Element for a Switch Port.
35 *
36 * @param switchDpid the Switch DPID.
37 * @param switchPort the Switch Port.
38 */
39 public TopologyElement(long switchDpid, int switchPort) {
40 this.elementType = Type.ELEMENT_PORT;
41 this.fromSwitchDpid = switchDpid;
42 this.fromSwitchPort = switchPort;
43 }
44
45 /**
46 * Constructor to create a Topology Element for an unidirectional Link
47 * between Switch Ports.
48 *
49 * @param fromSwitchDpid the Switch DPID the Link begins from.
50 * @param fromSwitchPort the Switch Port the Link begins from.
51 * @param toSwitchDpid the Switch DPID the Link ends to.
52 * @param toSwitchPort the Switch Port the Link ends to.
53 */
54 public TopologyElement(long fromSwitchDpid, int fromSwitchPort,
55 long toSwitchDpid, int toSwitchPort) {
56 this.elementType = Type.ELEMENT_LINK;
57 this.fromSwitchDpid = fromSwitchDpid;
58 this.fromSwitchPort = fromSwitchPort;
59 this.toSwitchDpid = toSwitchDpid;
60 this.toSwitchPort = toSwitchPort;
61 }
62
63 /**
64 * Get the Topology Element ID.
65 *
66 * The Topology Element ID has the following format:
67 * - Switch: "Switch=<Dpid>"
68 * Example: "Switch=00:00:00:00:00:00:00:01"
69 * - Switch Port: "Port=<Dpid>/<PortId>"
70 * Example: "Port=00:00:00:00:00:00:00:01/1"
71 * - Link: "Link=<FromDpid>/<FromPortId>/<ToDpid>/<ToPortId>"
72 * Example: "Link=00:00:00:00:00:00:00:01/1/00:00:00:00:00:00:00:02/1"
73 *
74 * @return the Topology Element ID.
75 */
76 public String elementId() {
77 switch (elementType) {
78 case ELEMENT_SWITCH:
79 return "Switch=" + fromSwitchDpid;
80 case ELEMENT_PORT:
81 return "Port=" + fromSwitchDpid + "/" + fromSwitchPort;
82 case ELEMENT_LINK:
83 return "Link=" + fromSwitchDpid + "/" + fromSwitchPort +
84 toSwitchDpid + "/" + toSwitchPort;
85 }
86
87 assert(false);
88 return null;
89 }
90}