sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 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.onosproject.segmentrouting; |
| 18 | |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 19 | import java.util.List; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 21 | |
| 22 | /** |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 23 | * Default Tunnel class. |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 24 | */ |
| 25 | public class DefaultTunnel implements Tunnel { |
| 26 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 27 | private final String id; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 28 | private final List<Integer> labelIds; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 29 | |
| 30 | private int groupId; |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 31 | private boolean allowedToRemoveGroup; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 32 | |
| 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) { |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 40 | 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); |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 44 | 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) { |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 53 | this.id = tunnel.id; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 54 | this.labelIds = tunnel.labelIds; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 55 | this.groupId = tunnel.groupId; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public String id() { |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 60 | return this.id; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public List<Integer> labelIds() { |
| 65 | return this.labelIds; |
| 66 | } |
| 67 | |
| 68 | @Override |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 69 | public int groupId() { |
| 70 | return this.groupId; |
| 71 | } |
| 72 | |
| 73 | @Override |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 74 | public void setGroupId(int id) { |
| 75 | this.groupId = id; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 76 | } |
| 77 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 78 | @Override |
| 79 | public boolean equals(Object o) { |
| 80 | if (this == o) { |
| 81 | return true; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 82 | } |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 83 | |
| 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; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 89 | } |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 90 | } |
| 91 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 92 | return false; |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 93 | } |
| 94 | |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 95 | @Override |
| 96 | public int hashCode() { |
HIGUCHI Yuta | 6ccc603 | 2015-10-29 23:26:51 -0700 | [diff] [blame] | 97 | return labelIds.hashCode(); |
sangho | 4a5c42a | 2015-05-20 22:16:38 -0700 | [diff] [blame] | 98 | } |
| 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 | } |
sangho | 27462c6 | 2015-05-14 00:39:53 -0700 | [diff] [blame] | 109 | } |