Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 2 | * Copyright 2011, Big Switch Networks, Inc. |
| 3 | * Originally created by David Erickson, Stanford University |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 5 | * not use this file except in compliance with the License. You may obtain |
| 6 | * a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations |
| 14 | * under the License. |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 15 | */ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 16 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 17 | package net.onrc.onos.core.linkdiscovery; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 18 | |
Jonathan Hart | 284e70f | 2014-07-05 12:32:51 -0700 | [diff] [blame] | 19 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService.LinkType; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 20 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 21 | import com.google.common.primitives.Longs; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 22 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Records information about a link. |
| 25 | */ |
| 26 | public final class LinkInfo { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 27 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | /** |
| 29 | * The port states stored here are topology's last knowledge of |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 30 | * the state of the port. This mostly mirrors the state |
| 31 | * maintained in the port list in IOFSwitch (i.e. the one returned |
| 32 | * from getPort), except that during a port status message the |
| 33 | * IOFSwitch port state will already have been updated with the |
| 34 | * new port state, so topology needs to keep its own copy so that |
| 35 | * it can determine if the port state has changed and therefore |
| 36 | * requires the new state to be written to storage. |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 37 | * |
| 38 | * Note the port state values are defined in the OF 1.0 spec. |
| 39 | * These will change in some way once we move to OF 1.3. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 40 | */ |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 41 | private final int srcPortState; |
| 42 | private final int dstPortState; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 43 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 44 | private final long firstSeenTime; |
| 45 | private final long lastLldpReceivedTime; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 46 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Constructs a LinkInfo object. |
| 49 | * |
| 50 | * @param firstSeenTime the timestamp when the link was first seen |
| 51 | * @param lastLldpReceivedTime the timestamp when the link was last seen |
| 52 | * @param srcPortState the port state of the source port |
| 53 | * @param dstPortState the port state of the destination port |
| 54 | */ |
| 55 | public LinkInfo(long firstSeenTime, |
| 56 | long lastLldpReceivedTime, |
| 57 | int srcPortState, |
| 58 | int dstPortState) { |
| 59 | this.srcPortState = srcPortState; |
| 60 | this.dstPortState = dstPortState; |
| 61 | this.firstSeenTime = firstSeenTime; |
| 62 | this.lastLldpReceivedTime = lastLldpReceivedTime; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Gets the timestamp when the link was first seen. |
| 67 | * |
| 68 | * @return the first seen timestamp |
| 69 | */ |
| 70 | public long getFirstSeenTime() { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 71 | return firstSeenTime; |
| 72 | } |
| 73 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 74 | /** |
| 75 | * Gets the timestamp when the link was last seen. |
| 76 | * |
| 77 | * @return the last seen timestamp |
| 78 | */ |
| 79 | public long getLastProbeReceivedTime() { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 80 | return lastLldpReceivedTime; |
| 81 | } |
| 82 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Gets the state of the source port. |
| 85 | * |
| 86 | * @return the source port state, as defined in the OF1.0 spec |
| 87 | */ |
| 88 | public int getSrcPortState() { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 89 | return srcPortState; |
| 90 | } |
| 91 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 92 | /** |
| 93 | * Gets the state of the destination port. |
| 94 | * |
| 95 | * @return the destination port state, as defined in the OF1.0 spec |
| 96 | */ |
| 97 | public int getDstPortState() { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 98 | return dstPortState; |
| 99 | } |
| 100 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 101 | /** |
| 102 | * Gets the link type. |
| 103 | * |
| 104 | * @return the link type |
| 105 | * @see LinkType |
| 106 | */ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 107 | public LinkType getLinkType() { |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 108 | return LinkType.DIRECT_LINK; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* (non-Javadoc) |
| 112 | * @see java.lang.Object#hashCode() |
| 113 | */ |
| 114 | @Override |
| 115 | public int hashCode() { |
| 116 | final int prime = 5557; |
| 117 | int result = 1; |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 118 | result = prime * result + Longs.hashCode(firstSeenTime); |
| 119 | result = prime * result + Longs.hashCode(lastLldpReceivedTime); |
| 120 | result = prime * result + srcPortState; |
| 121 | result = prime * result + dstPortState; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 122 | return result; |
| 123 | } |
| 124 | |
| 125 | /* (non-Javadoc) |
| 126 | * @see java.lang.Object#equals(java.lang.Object) |
| 127 | */ |
| 128 | @Override |
| 129 | public boolean equals(Object obj) { |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 130 | if (this == obj) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 131 | return true; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 132 | } |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 133 | |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 134 | if (!(obj instanceof LinkInfo)) { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 135 | return false; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 136 | } |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 137 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 138 | LinkInfo other = (LinkInfo) obj; |
| 139 | |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 140 | return firstSeenTime == other.firstSeenTime && |
| 141 | lastLldpReceivedTime == other.lastLldpReceivedTime && |
| 142 | srcPortState == other.srcPortState && |
| 143 | dstPortState == other.dstPortState; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
| 147 | /* (non-Javadoc) |
| 148 | * @see java.lang.Object#toString() |
| 149 | */ |
| 150 | @Override |
| 151 | public String toString() { |
Jonathan Hart | cd1ab17 | 2014-07-03 14:59:48 -0700 | [diff] [blame] | 152 | return "LinkInfo [unicastValidTime=" + lastLldpReceivedTime |
| 153 | + ", srcPortState=" + srcPortState |
| 154 | + ", dstPortState=" + dstPortState |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 155 | + "]"; |
| 156 | } |
| 157 | } |