blob: fc8bbe5ddbe743a5f665a4fe40a6a1ed0ff0d12d [file] [log] [blame]
jiangrui181166e2015-11-12 11:34:48 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui181166e2015-11-12 11:34:48 +08003 *
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.vtnrsc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.List;
22import java.util.Objects;
23
24/**
25 * Default implementation of router interface.
26 */
27public final class DefaultRouter implements Router {
28 private final RouterId id;
29 private final String name;
30 private final boolean adminStateUp;
31 private final Status status;
32 private final boolean distributed;
33 private final RouterGateway externalGatewayInfo;
34 private final VirtualPortId gatewayPortId;
35 private final TenantId tenantId;
36 private final List<String> routes;
37
38 /**
39 * Creates router object.
40 *
41 * @param id router identifier
42 * @param routerName the name of router
43 * @param adminStateUp the status of admin state
44 * @param status the status of router
45 * @param distributed the status of router distributed
46 * @param externalGatewayInfo the gateway info of router
47 * @param gatewayPortId the port identifier of router gateway
48 * @param tenantId the tenant identifier
49 * @param routes the routes configure
50 */
51 public DefaultRouter(RouterId id, String routerName, boolean adminStateUp,
52 Status status, boolean distributed,
53 RouterGateway externalGatewayInfo,
54 VirtualPortId gatewayPortId, TenantId tenantId,
55 List<String> routes) {
56 this.id = checkNotNull(id, "id cannot be null");
57 this.name = routerName;
Yuta HIGUCHIfbd9ae92018-01-24 23:39:06 -080058 this.adminStateUp = adminStateUp;
jiangrui181166e2015-11-12 11:34:48 +080059 this.status = checkNotNull(status, "status cannot be null");
Yuta HIGUCHIfbd9ae92018-01-24 23:39:06 -080060 this.distributed = distributed;
jiangrui181166e2015-11-12 11:34:48 +080061 this.externalGatewayInfo = externalGatewayInfo;
62 this.gatewayPortId = gatewayPortId;
63 this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
64 this.routes = routes;
65 }
66
67 @Override
68 public RouterId id() {
69 return id;
70 }
71
72 @Override
73 public String name() {
74 return name;
75 }
76
77 @Override
78 public boolean adminStateUp() {
79 return adminStateUp;
80 }
81
82 @Override
83 public Status status() {
84 return status;
85 }
86
87 @Override
88 public boolean distributed() {
89 return distributed;
90 }
91
92 @Override
93 public RouterGateway externalGatewayInfo() {
94 return externalGatewayInfo;
95 }
96
97 @Override
98 public VirtualPortId gatewayPortid() {
99 return gatewayPortId;
100 }
101
102 @Override
103 public TenantId tenantId() {
104 return tenantId;
105 }
106
107 @Override
108 public List<String> routes() {
109 return routes;
110 }
111
112 @Override
113 public int hashCode() {
114 return Objects.hash(id, name, adminStateUp, status, distributed,
115 externalGatewayInfo, gatewayPortId, routes);
116 }
117
118 @Override
119 public boolean equals(Object obj) {
120 if (this == obj) {
121 return true;
122 }
123 if (obj instanceof DefaultRouter) {
124 final DefaultRouter that = (DefaultRouter) obj;
125 return Objects.equals(this.id, that.id)
126 && Objects.equals(this.name, that.name)
127 && Objects.equals(this.adminStateUp, that.adminStateUp)
128 && Objects.equals(this.status, that.status)
129 && Objects.equals(this.distributed, that.distributed)
130 && Objects.equals(this.externalGatewayInfo,
131 that.externalGatewayInfo)
132 && Objects.equals(this.gatewayPortId, that.gatewayPortId)
133 && Objects.equals(this.routes, that.routes);
134 }
135 return false;
136 }
137
138 @Override
139 public String toString() {
140 return toStringHelper(this).add("id", id).add("routerName", name)
141 .add("adminStateUp", adminStateUp).add("status", status)
142 .add("distributed", distributed)
143 .add("externalGatewayInfo", externalGatewayInfo)
144 .add("gatewayPortid", gatewayPortId).add("routes", routes).toString();
145 }
146}