blob: 2fded10eb684ccae959203e4906a2708802eaefa [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 Koidea03915e2014-07-01 18:39:52 -07004import net.onrc.onos.core.util.Dpid;
5import net.onrc.onos.core.util.PortNumber;
6import net.onrc.onos.core.util.SwitchPort;
7
8/**
Toshio Koide7894ca02014-08-15 14:30:13 -07009 * A link representation used by Flow objects.
Toshio Koidea03915e2014-07-01 18:39:52 -070010 * <p>
11 * TODO: Should lambda, bandwidth, tag, etc. be defined in this FlowLink, Path,
Toshio Koide7894ca02014-08-15 14:30:13 -070012 * Tree or Flow? We have to define it.
Toshio Koidea03915e2014-07-01 18:39:52 -070013 */
14public class FlowLink {
15 protected SwitchPort srcSwitchPort;
16 protected SwitchPort dstSwitchPort;
17
18 /**
19 * Creates new FlowLink object using source/destination switch port pair.
20 *
21 * @param src The source switch port.
22 * @param dst The destination switch port.
23 */
24 public FlowLink(SwitchPort src, SwitchPort dst) {
25 this.srcSwitchPort = src;
26 this.dstSwitchPort = dst;
27 }
28
29 /**
30 * Creates new FlowLink object using DPID and port number pairs at
31 * source/destination switches.
32 *
33 * @param srcDpid The source switch DPID.
34 * @param srcPortNumber The source port number at the source switch.
35 * @param dstDpid The destination switch DPID.
36 * @param dstPortNumber The destination port number at the destination
37 * switch.
38 */
39 public FlowLink(Dpid srcDpid, PortNumber srcPortNumber,
40 Dpid dstDpid, PortNumber dstPortNumber) {
41 this.srcSwitchPort = new SwitchPort(srcDpid, srcPortNumber);
42 this.dstSwitchPort = new SwitchPort(dstDpid, dstPortNumber);
43 }
44
45 /**
46 * Gets the source switch port.
47 *
48 * @return The source switch port.
49 */
50 public SwitchPort getSrcSwitchPort() {
51 return srcSwitchPort;
52 }
53
54 /**
55 * Gets the source switch DPID.
56 *
57 * @return The source switch DPID.
58 */
59 public Dpid getSrcDpid() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -070060 return srcSwitchPort.getDpid();
Toshio Koidea03915e2014-07-01 18:39:52 -070061 }
62
63 /**
64 * Gets the source port number at the source switch.
65 *
66 * @return The source port number at the source switch.
67 */
68 public PortNumber getSrcPortNumber() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -070069 return srcSwitchPort.getPortNumber();
Toshio Koidea03915e2014-07-01 18:39:52 -070070 }
71
72 /**
73 * Gets the destination switch port.
74 *
75 * @return The destination switch port.
76 */
77 public SwitchPort getDstSwitchPort() {
78 return dstSwitchPort;
79 }
80
81 /**
82 * Gets the destination switch DPID.
83 *
84 * @return The destination switch DPID.
85 */
86 public Dpid getDstDpid() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -070087 return dstSwitchPort.getDpid();
Toshio Koidea03915e2014-07-01 18:39:52 -070088 }
89
90 /**
91 * Gets the destination port number at the destination switch.
92 *
93 * @return The destination port number at the destination switch.
94 */
95 public PortNumber getDstPortNumber() {
Pavlin Radoslavov3d322f42014-08-18 14:58:55 -070096 return dstSwitchPort.getPortNumber();
Toshio Koidea03915e2014-07-01 18:39:52 -070097 }
98
99 @Override
100 public String toString() {
101 return srcSwitchPort + "-->" + dstSwitchPort;
102 }
Sho SHIMIZU25d68f62014-08-21 18:26:26 -0700103
104 @Override
105 public boolean equals(Object o) {
106 if (this == o) {
107 return true;
108 }
109 if (o == null || getClass() != o.getClass()) {
110 return false;
111 }
112
113 FlowLink that = (FlowLink) o;
114 return Objects.equal(this.srcSwitchPort, that.srcSwitchPort)
115 && Objects.equal(this.dstSwitchPort, that.dstSwitchPort);
116 }
117
118 @Override
119 public int hashCode() {
120 return Objects.hashCode(srcSwitchPort, dstSwitchPort);
121 }
Toshio Koidea03915e2014-07-01 18:39:52 -0700122}