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 | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 4 | import net.onrc.onos.core.util.Dpid; |
| 5 | import net.onrc.onos.core.util.PortNumber; |
| 6 | import net.onrc.onos.core.util.SwitchPort; |
| 7 | |
| 8 | /** |
Toshio Koide | 7894ca0 | 2014-08-15 14:30:13 -0700 | [diff] [blame] | 9 | * A link representation used by Flow objects. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 10 | * <p> |
| 11 | * TODO: Should lambda, bandwidth, tag, etc. be defined in this FlowLink, Path, |
Toshio Koide | 7894ca0 | 2014-08-15 14:30:13 -0700 | [diff] [blame] | 12 | * Tree or Flow? We have to define it. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 13 | */ |
| 14 | public 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 60 | return srcSwitchPort.getDpid(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 61 | } |
| 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 69 | return srcSwitchPort.getPortNumber(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 70 | } |
| 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 87 | return dstSwitchPort.getDpid(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 88 | } |
| 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 Radoslavov | 3d322f4 | 2014-08-18 14:58:55 -0700 | [diff] [blame] | 96 | return dstSwitchPort.getPortNumber(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return srcSwitchPort + "-->" + dstSwitchPort; |
| 102 | } |
Sho SHIMIZU | 25d68f6 | 2014-08-21 18:26:26 -0700 | [diff] [blame^] | 103 | |
| 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 122 | } |