blob: d4f0638e706d5d2be8e85f82d82ce2668976d9f4 [file] [log] [blame]
Aihua Guo1ce2dd12016-08-12 23:37:44 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Aihua Guo1ce2dd12016-08-12 23:37:44 -04003 *
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 */
16package org.onosproject.tetopology.management.api.link;
17
Henry Yu4b4a7eb2016-11-09 20:07:53 -050018import com.google.common.base.MoreObjects;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040019import org.onlab.packet.IpAddress;
20
Henry Yu4b4a7eb2016-11-09 20:07:53 -050021import java.util.Objects;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040022
23/**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050024 * Implementation of unnumbered link as an element type.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040025 */
26public class UnnumberedLink implements ElementType {
Henry Yu4b4a7eb2016-11-09 20:07:53 -050027 private final IpAddress routerId;
28 private final long interfaceId;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040029
30 /**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050031 * Creates a unnumbered link.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040032 *
Henry Yu4b4a7eb2016-11-09 20:07:53 -050033 * @param routerId the router id to set
34 * @param interfaceId the interface id to set
Aihua Guo1ce2dd12016-08-12 23:37:44 -040035 */
Henry Yu4b4a7eb2016-11-09 20:07:53 -050036 public UnnumberedLink(IpAddress routerId, long interfaceId) {
Aihua Guo1ce2dd12016-08-12 23:37:44 -040037 this.routerId = routerId;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040038 this.interfaceId = interfaceId;
39 }
40
41 /**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050042 * Returns the router identifier.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040043 *
Henry Yu4b4a7eb2016-11-09 20:07:53 -050044 * @return router id
Aihua Guo1ce2dd12016-08-12 23:37:44 -040045 */
46 public IpAddress routerId() {
47 return routerId;
48 }
49
50 /**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050051 * Returns the interface identifier.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040052 *
Henry Yu4b4a7eb2016-11-09 20:07:53 -050053 * @return interface id
Aihua Guo1ce2dd12016-08-12 23:37:44 -040054 */
55 public long interfaceId() {
56 return interfaceId;
57 }
58
59 @Override
60 public int hashCode() {
61 return Objects.hash(routerId, interfaceId);
62 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (this == obj) {
67 return true;
68 }
69 if (obj instanceof UnnumberedLink) {
70 UnnumberedLink other = (UnnumberedLink) obj;
71 return
Henry Yu4b4a7eb2016-11-09 20:07:53 -050072 Objects.equals(routerId, other.routerId) &&
73 Objects.equals(interfaceId, other.interfaceId);
Aihua Guo1ce2dd12016-08-12 23:37:44 -040074 }
75 return false;
76 }
77
78 @Override
79 public String toString() {
80 return MoreObjects.toStringHelper(getClass())
Henry Yu4b4a7eb2016-11-09 20:07:53 -050081 .add("routerId", routerId)
82 .add("interfaceId", interfaceId)
83 .toString();
Aihua Guo1ce2dd12016-08-12 23:37:44 -040084 }
85}