amit.ghosh | 6104cf5 | 2021-01-07 16:53:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain 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, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.opencord.olttopology; |
| 18 | |
| 19 | import org.onlab.packet.LLDPTLV; |
| 20 | |
| 21 | import org.onosproject.net.Port; |
| 22 | |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.Date; |
| 25 | import java.util.List; |
| 26 | import java.util.Objects; |
| 27 | |
| 28 | /** |
| 29 | * Information about an OLT's neighbor. An instance of this class stores |
| 30 | * information about an OLT and it's neighbour. The information contains |
| 31 | * which port of the OLT is connected to which port of the neighbor |
| 32 | */ |
| 33 | public class OltNeighborInfo { |
| 34 | |
| 35 | private String neighborName; |
| 36 | private String neighborPort; |
| 37 | private String oltName; |
| 38 | private Port oltPort; |
| 39 | |
| 40 | // Serial number of the OLT |
| 41 | private String oltSerialNo; |
| 42 | |
| 43 | // The management IP address of the neighbor |
| 44 | private String mgmtAddr; |
| 45 | |
| 46 | // The time when this entry was last updated |
| 47 | private Date lastUpdated; |
| 48 | |
| 49 | // List of other optional TLVs that would have been received from the |
| 50 | // neighbor in the last LLDP message |
| 51 | private List<LLDPTLV> otherOptionalTlvs; |
| 52 | |
| 53 | public OltNeighborInfo(String neighborName, String neighborPort, |
| 54 | String oltName, Port oltPort, String oltSerialNo) { |
| 55 | this.neighborName = neighborName; |
| 56 | this.neighborPort = neighborPort; |
| 57 | this.oltName = oltName; |
| 58 | this.oltPort = oltPort; |
| 59 | this.oltSerialNo = oltSerialNo; |
| 60 | otherOptionalTlvs = new ArrayList<>(); |
| 61 | updateTimeStamp(); |
| 62 | } |
| 63 | |
| 64 | public String neighborName() { |
| 65 | return neighborName; |
| 66 | } |
| 67 | |
| 68 | public String neighborPort() { |
| 69 | return neighborPort; |
| 70 | } |
| 71 | |
| 72 | public String oltName() { |
| 73 | return oltName; |
| 74 | } |
| 75 | |
| 76 | public Port oltPort() { |
| 77 | return oltPort; |
| 78 | } |
| 79 | |
| 80 | public String oltSerialNo() { |
| 81 | return oltSerialNo; |
| 82 | } |
| 83 | |
| 84 | public Date getLastUpdated() { |
| 85 | return lastUpdated; |
| 86 | } |
| 87 | |
| 88 | public void updateTimeStamp() { |
| 89 | lastUpdated = new Date(); |
| 90 | } |
| 91 | |
| 92 | public String mgmtAddr() { |
| 93 | return mgmtAddr; |
| 94 | } |
| 95 | |
| 96 | public void setMgmtAddress(String neighborManagementAddress) { |
| 97 | mgmtAddr = neighborManagementAddress; |
| 98 | } |
| 99 | |
| 100 | public void addOtherOptionalLldpTlvs(LLDPTLV lldptlv) { |
| 101 | otherOptionalTlvs.add(lldptlv); |
| 102 | } |
| 103 | |
| 104 | public List<LLDPTLV> getOtherOptionalTlvs() { |
| 105 | return otherOptionalTlvs; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public boolean equals(Object o) { |
| 110 | if (this == o) { |
| 111 | return true; |
| 112 | } |
| 113 | if (o == null || getClass() != o.getClass()) { |
| 114 | return false; |
| 115 | } |
| 116 | OltNeighborInfo that = (OltNeighborInfo) o; |
| 117 | return Objects.equals(neighborName, that.neighborName) && |
| 118 | Objects.equals(neighborPort, that.neighborPort) && |
| 119 | Objects.equals(oltName, that.oltName) && |
| 120 | Objects.equals(oltPort, that.oltPort) && |
| 121 | Objects.equals(oltSerialNo, that.oltSerialNo) && |
| 122 | Objects.equals(mgmtAddr, that.mgmtAddr) && |
| 123 | Objects.equals(lastUpdated, that.lastUpdated); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public int hashCode() { |
| 128 | return Objects.hash(neighborName, neighborPort, oltName, |
| 129 | oltPort, oltSerialNo, mgmtAddr, lastUpdated); |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * (non-Javadoc) |
| 134 | * |
| 135 | * @see java.lang.Object#toString() |
| 136 | */ |
| 137 | @Override |
| 138 | public String toString() { |
| 139 | final StringBuilder buf = new StringBuilder(); |
| 140 | buf.append('['); |
| 141 | buf.append("neighborName:"); |
| 142 | buf.append(this.neighborName); |
| 143 | buf.append(",neighborPort:"); |
| 144 | buf.append(this.neighborPort); |
| 145 | buf.append(",oltName:"); |
| 146 | buf.append(this.oltName); |
| 147 | buf.append(",oltPort:"); |
| 148 | buf.append((this.oltPort.annotations().value("portName").isEmpty()) ? "" : |
| 149 | this.oltPort.annotations().value("portName")); |
| 150 | buf.append(",oltSerialNo:"); |
| 151 | buf.append(this.oltSerialNo); |
| 152 | buf.append(",neighbor_mgmt_address:"); |
| 153 | buf.append(this.mgmtAddr); |
| 154 | buf.append(",lastUpdated:"); |
| 155 | buf.append(this.lastUpdated); |
| 156 | buf.append(']'); |
| 157 | return buf.toString(); |
| 158 | } |
| 159 | } |