Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.flowmanager; |
| 2 | |
Sho SHIMIZU | 25d68f6 | 2014-08-21 18:26:26 -0700 | [diff] [blame] | 3 | import com.google.common.base.Objects; |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 4 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.Dpid; |
| 6 | import net.onrc.onos.core.util.PortNumber; |
| 7 | import net.onrc.onos.core.util.SwitchPort; |
| 8 | |
| 9 | /** |
Toshio Koide | 7894ca0 | 2014-08-15 14:30:13 -0700 | [diff] [blame] | 10 | * A link representation used by Flow objects. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 11 | * <p> |
| 12 | * TODO: Should lambda, bandwidth, tag, etc. be defined in this FlowLink, Path, |
Toshio Koide | 7894ca0 | 2014-08-15 14:30:13 -0700 | [diff] [blame] | 13 | * Tree or Flow? We have to define it. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 14 | */ |
| 15 | public class FlowLink { |
| 16 | protected SwitchPort srcSwitchPort; |
| 17 | protected SwitchPort dstSwitchPort; |
| 18 | |
| 19 | /** |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 20 | * Default constructor for Kryo deserialization. |
| 21 | */ |
| 22 | @Deprecated |
| 23 | protected FlowLink() { |
| 24 | srcSwitchPort = null; |
| 25 | dstSwitchPort = null; |
| 26 | } |
| 27 | |
| 28 | /** |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 29 | * 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 70 | return srcSwitchPort.getDpid(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 71 | } |
| 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 79 | return srcSwitchPort.getPortNumber(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 80 | } |
| 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 97 | return dstSwitchPort.getDpid(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 98 | } |
| 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 106 | return dstSwitchPort.getPortNumber(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public String toString() { |
| 111 | return srcSwitchPort + "-->" + dstSwitchPort; |
| 112 | } |
Sho SHIMIZU | 25d68f6 | 2014-08-21 18:26:26 -0700 | [diff] [blame] | 113 | |
| 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 132 | } |