blob: 0c2400cd346d61aa8a76421833cb83088a1f1c6d [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Jonathan Hartcd1ab172014-07-03 14:59:48 -07002 * 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 Milkey269ffb92014-04-03 14:43:30 -07005 * 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 Hartcd1ab172014-07-03 14:59:48 -070015 */
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080016
Jonathan Hart23701d12014-04-03 10:45:48 -070017package net.onrc.onos.core.linkdiscovery;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080018
Jonathan Hart23701d12014-04-03 10:45:48 -070019import net.onrc.onos.core.linkdiscovery.ILinkDiscovery.LinkType;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080020
Jonathan Hartcd1ab172014-07-03 14:59:48 -070021import com.google.common.primitives.Longs;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022
Jonathan Hartcd1ab172014-07-03 14:59:48 -070023/**
24 * Records information about a link.
25 */
26public final class LinkInfo {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080027
Ray Milkey269ffb92014-04-03 14:43:30 -070028 /**
29 * The port states stored here are topology's last knowledge of
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080030 * 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 Hartcd1ab172014-07-03 14:59:48 -070037 *
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 Krishnaswamy345ee992012-12-13 20:29:48 -080040 */
Jonathan Hartcd1ab172014-07-03 14:59:48 -070041 private final int srcPortState;
42 private final int dstPortState;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080043
Jonathan Hartcd1ab172014-07-03 14:59:48 -070044 private final long firstSeenTime;
45 private final long lastLldpReceivedTime;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046
Jonathan Hartcd1ab172014-07-03 14:59:48 -070047 /**
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 Krishnaswamy345ee992012-12-13 20:29:48 -080063 }
64
Jonathan Hartcd1ab172014-07-03 14:59:48 -070065 /**
66 * Gets the timestamp when the link was first seen.
67 *
68 * @return the first seen timestamp
69 */
70 public long getFirstSeenTime() {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080071 return firstSeenTime;
72 }
73
Jonathan Hartcd1ab172014-07-03 14:59:48 -070074 /**
75 * Gets the timestamp when the link was last seen.
76 *
77 * @return the last seen timestamp
78 */
79 public long getLastProbeReceivedTime() {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080080 return lastLldpReceivedTime;
81 }
82
Jonathan Hartcd1ab172014-07-03 14:59:48 -070083 /**
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 Krishnaswamy345ee992012-12-13 20:29:48 -080089 return srcPortState;
90 }
91
Jonathan Hartcd1ab172014-07-03 14:59:48 -070092 /**
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 Krishnaswamy345ee992012-12-13 20:29:48 -080098 return dstPortState;
99 }
100
Jonathan Hartcd1ab172014-07-03 14:59:48 -0700101 /**
102 * Gets the link type.
103 *
104 * @return the link type
105 * @see LinkType
106 */
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800107 public LinkType getLinkType() {
Jonathan Hartcd1ab172014-07-03 14:59:48 -0700108 return LinkType.DIRECT_LINK;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800109 }
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 Hartcd1ab172014-07-03 14:59:48 -0700118 result = prime * result + Longs.hashCode(firstSeenTime);
119 result = prime * result + Longs.hashCode(lastLldpReceivedTime);
120 result = prime * result + srcPortState;
121 result = prime * result + dstPortState;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800122 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 Milkeyb29e6262014-04-09 16:02:14 -0700130 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800131 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700132 }
Jonathan Hartcd1ab172014-07-03 14:59:48 -0700133
Ray Milkeyb29e6262014-04-09 16:02:14 -0700134 if (!(obj instanceof LinkInfo)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800135 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700136 }
Jonathan Hartcd1ab172014-07-03 14:59:48 -0700137
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800138 LinkInfo other = (LinkInfo) obj;
139
Jonathan Hartcd1ab172014-07-03 14:59:48 -0700140 return firstSeenTime == other.firstSeenTime &&
141 lastLldpReceivedTime == other.lastLldpReceivedTime &&
142 srcPortState == other.srcPortState &&
143 dstPortState == other.dstPortState;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800144 }
145
146
147 /* (non-Javadoc)
148 * @see java.lang.Object#toString()
149 */
150 @Override
151 public String toString() {
Jonathan Hartcd1ab172014-07-03 14:59:48 -0700152 return "LinkInfo [unicastValidTime=" + lastLldpReceivedTime
153 + ", srcPortState=" + srcPortState
154 + ", dstPortState=" + dstPortState
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800155 + "]";
156 }
157}