blob: 871f00307ff236f74a40ce82c6377e4f4a12de5e [file] [log] [blame]
sangho27462c62015-05-14 00:39:53 -07001/*
Brian O'Connor43b53542016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
sangho27462c62015-05-14 00:39:53 -07003 *
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
17package org.onosproject.segmentrouting;
18
sangho27462c62015-05-14 00:39:53 -070019import java.util.List;
sangho27462c62015-05-14 00:39:53 -070020import static com.google.common.base.Preconditions.checkNotNull;
21
22/**
Charles Chanb7f75ac2016-01-11 18:28:54 -080023 * Default Tunnel class.
sangho27462c62015-05-14 00:39:53 -070024 */
25public class DefaultTunnel implements Tunnel {
26
sangho4a5c42a2015-05-20 22:16:38 -070027 private final String id;
sangho27462c62015-05-14 00:39:53 -070028 private final List<Integer> labelIds;
sangho27462c62015-05-14 00:39:53 -070029
30 private int groupId;
sangho4a5c42a2015-05-20 22:16:38 -070031 private boolean allowedToRemoveGroup;
sangho27462c62015-05-14 00:39:53 -070032
33 /**
34 * Creates a Tunnel reference.
35 *
36 * @param tid Tunnel ID
37 * @param labelIds Label stack of the tunnel
38 */
39 public DefaultTunnel(String tid, List<Integer> labelIds) {
sangho4a5c42a2015-05-20 22:16:38 -070040 this.id = checkNotNull(tid);
41 this.labelIds = labelIds;
42 //TODO: need to register the class in Kryo for this
43 //this.labelIds = Collections.unmodifiableList(labelIds);
sangho27462c62015-05-14 00:39:53 -070044 this.groupId = -1;
45 }
46
47 /**
48 * Creates a new DefaultTunnel reference using the tunnel reference.
49 *
50 * @param tunnel DefaultTunnel reference
51 */
52 public DefaultTunnel(DefaultTunnel tunnel) {
sangho4a5c42a2015-05-20 22:16:38 -070053 this.id = tunnel.id;
sangho27462c62015-05-14 00:39:53 -070054 this.labelIds = tunnel.labelIds;
sangho27462c62015-05-14 00:39:53 -070055 this.groupId = tunnel.groupId;
56 }
57
58 @Override
59 public String id() {
sangho4a5c42a2015-05-20 22:16:38 -070060 return this.id;
sangho27462c62015-05-14 00:39:53 -070061 }
62
63 @Override
64 public List<Integer> labelIds() {
65 return this.labelIds;
66 }
67
68 @Override
sangho27462c62015-05-14 00:39:53 -070069 public int groupId() {
70 return this.groupId;
71 }
72
73 @Override
sangho4a5c42a2015-05-20 22:16:38 -070074 public void setGroupId(int id) {
75 this.groupId = id;
sangho27462c62015-05-14 00:39:53 -070076 }
77
sangho4a5c42a2015-05-20 22:16:38 -070078 @Override
79 public boolean equals(Object o) {
80 if (this == o) {
81 return true;
sangho27462c62015-05-14 00:39:53 -070082 }
sangho4a5c42a2015-05-20 22:16:38 -070083
84 if (o instanceof DefaultTunnel) {
85 DefaultTunnel tunnel = (DefaultTunnel) o;
86 // We compare only the tunnel paths.
87 if (tunnel.labelIds.equals(this.labelIds)) {
88 return true;
sangho27462c62015-05-14 00:39:53 -070089 }
sangho27462c62015-05-14 00:39:53 -070090 }
91
sangho4a5c42a2015-05-20 22:16:38 -070092 return false;
sangho27462c62015-05-14 00:39:53 -070093 }
94
sangho4a5c42a2015-05-20 22:16:38 -070095 @Override
96 public int hashCode() {
HIGUCHI Yuta6ccc6032015-10-29 23:26:51 -070097 return labelIds.hashCode();
sangho4a5c42a2015-05-20 22:16:38 -070098 }
99
100 @Override
101 public boolean isAllowedToRemoveGroup() {
102 return this.allowedToRemoveGroup;
103 }
104
105 @Override
106 public void allowToRemoveGroup(boolean b) {
107 this.allowedToRemoveGroup = b;
108 }
sangho27462c62015-05-14 00:39:53 -0700109}