blob: 5a3f26b5255071043dd80b65f7e277fb93727960 [file] [log] [blame]
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070016package org.onosproject.segmentrouting.grouphandler;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080017
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.List;
21import java.util.Objects;
22
23import org.onosproject.net.PortNumber;
24
25/**
26 * Representation of parameters used to create policy based groups.
27 */
28public class PolicyGroupParams {
29 private final List<PortNumber> ports;
30 private final List<Integer> labelStack;
31
32 /**
33 * Constructor.
34 *
35 * @param labelStack mpls label stack to be applied on the ports
36 * @param ports ports to be part of the policy group
37 */
38 public PolicyGroupParams(List<Integer> labelStack,
39 List<PortNumber> ports) {
40 this.ports = checkNotNull(ports);
41 this.labelStack = checkNotNull(labelStack);
42 }
43
44 /**
45 * Returns the ports associated with the policy group params.
46 *
47 * @return list of port numbers
48 */
49 public List<PortNumber> getPorts() {
50 return ports;
51 }
52
53 /**
54 * Returns the label stack associated with the policy group params.
55 *
56 * @return list of integers
57 */
58 public List<Integer> getLabelStack() {
59 return labelStack;
60 }
61
62 @Override
63 public int hashCode() {
64 int result = 17;
65 int combinedHash = 0;
66 for (PortNumber port:ports) {
67 combinedHash = combinedHash + port.hashCode();
68 }
69 combinedHash = combinedHash + Objects.hash(labelStack);
70 result = 31 * result + combinedHash;
71
72 return result;
73 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj) {
78 return true;
79 }
80
81 if (obj instanceof PolicyGroupParams) {
82 PolicyGroupParams that = (PolicyGroupParams) obj;
83 boolean result = this.labelStack.equals(that.labelStack);
84 result = result &&
85 this.ports.containsAll(that.ports) &&
86 that.ports.containsAll(this.ports);
87 return result;
88 }
89
90 return false;
91 }
92}