blob: 8b8ad75abeb67765477ffa29ac392acb3bcaa6c1 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.api.flowmanager;
2
Sho SHIMIZU25d68f62014-08-21 18:26:26 -07003import com.google.common.base.Objects;
Toshio Koide2c67a2d2014-08-27 11:30:56 -07004
Toshio Koidea03915e2014-07-01 18:39:52 -07005import net.onrc.onos.core.util.Dpid;
6import net.onrc.onos.core.util.PortNumber;
7import net.onrc.onos.core.util.SwitchPort;
8
9/**
Toshio Koide7894ca02014-08-15 14:30:13 -070010 * A link representation used by Flow objects.
Toshio Koidea03915e2014-07-01 18:39:52 -070011 * <p>
12 * TODO: Should lambda, bandwidth, tag, etc. be defined in this FlowLink, Path,
Toshio Koide7894ca02014-08-15 14:30:13 -070013 * Tree or Flow? We have to define it.
Toshio Koidea03915e2014-07-01 18:39:52 -070014 */
15public class FlowLink {
16 protected SwitchPort srcSwitchPort;
17 protected SwitchPort dstSwitchPort;
18
19 /**
Toshio Koide2c67a2d2014-08-27 11:30:56 -070020 * Default constructor for Kryo deserialization.
21 */
22 @Deprecated
23 protected FlowLink() {
24 srcSwitchPort = null;
25 dstSwitchPort = null;
26 }
27
28 /**
Toshio Koidea03915e2014-07-01 18:39:52 -070029 * Creates new FlowLink object using source/destination switch port pair.
30 *
31 * @param src The source switch port.
32 * @param dst The destination switch port.
33 */
34 public FlowLink(SwitchPort src, SwitchPort dst) {
35 this.srcSwitchPort = src;
36 this.dstSwitchPort = dst;
37 }
38
39 /**
40 * Creates new FlowLink object using DPID and port number pairs at
41 * source/destination switches.
42 *
43 * @param srcDpid The source switch DPID.
44 * @param srcPortNumber The source port number at the source switch.
45 * @param dstDpid The destination switch DPID.
46 * @param dstPortNumber The destination port number at the destination
47 * switch.
48 */
49 public FlowLink(Dpid srcDpid, PortNumber srcPortNumber,
50 Dpid dstDpid, PortNumber dstPortNumber) {
51 this.srcSwitchPort = new SwitchPort(srcDpid, srcPortNumber);
52 this.dstSwitchPort = new SwitchPort(dstDpid, dstPortNumber);
53 }
54
55 /**
56 * Gets the source switch port.
57 *
58 * @return The source switch port.
59 */
60 public SwitchPort getSrcSwitchPort() {
61 return srcSwitchPort;
62 }
63
64 /**
65 * Gets the source switch DPID.
66 *
67 * @return The source switch DPID.
68 */
69 public Dpid getSrcDpid() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -070070 return srcSwitchPort.getDpid();
Toshio Koidea03915e2014-07-01 18:39:52 -070071 }
72
73 /**
74 * Gets the source port number at the source switch.
75 *
76 * @return The source port number at the source switch.
77 */
78 public PortNumber getSrcPortNumber() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -070079 return srcSwitchPort.getPortNumber();
Toshio Koidea03915e2014-07-01 18:39:52 -070080 }
81
82 /**
83 * Gets the destination switch port.
84 *
85 * @return The destination switch port.
86 */
87 public SwitchPort getDstSwitchPort() {
88 return dstSwitchPort;
89 }
90
91 /**
92 * Gets the destination switch DPID.
93 *
94 * @return The destination switch DPID.
95 */
96 public Dpid getDstDpid() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -070097 return dstSwitchPort.getDpid();
Toshio Koidea03915e2014-07-01 18:39:52 -070098 }
99
100 /**
101 * Gets the destination port number at the destination switch.
102 *
103 * @return The destination port number at the destination switch.
104 */
105 public PortNumber getDstPortNumber() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -0700106 return dstSwitchPort.getPortNumber();
Toshio Koidea03915e2014-07-01 18:39:52 -0700107 }
108
109 @Override
110 public String toString() {
111 return srcSwitchPort + "-->" + dstSwitchPort;
112 }
Sho SHIMIZU25d68f62014-08-21 18:26:26 -0700113
114 @Override
115 public boolean equals(Object o) {
116 if (this == o) {
117 return true;
118 }
119 if (o == null || getClass() != o.getClass()) {
120 return false;
121 }
122
123 FlowLink that = (FlowLink) o;
124 return Objects.equal(this.srcSwitchPort, that.srcSwitchPort)
125 && Objects.equal(this.dstSwitchPort, that.dstSwitchPort);
126 }
127
128 @Override
129 public int hashCode() {
130 return Objects.hashCode(srcSwitchPort, dstSwitchPort);
131 }
Toshio Koidea03915e2014-07-01 18:39:52 -0700132}