blob: b2f05116251d6707053761ebf23a9155b81f8c24 [file] [log] [blame]
Shashikanth VHfb391ae2016-02-04 18:15:05 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Shashikanth VHfb391ae2016-02-04 18:15:05 +05303 *
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.bgpio.protocol.flowspec;
17
18import java.util.Iterator;
19import java.util.List;
20import java.util.Objects;
21import org.onosproject.bgpio.types.BgpValueType;
22import org.onosproject.bgpio.types.RouteDistinguisher;
23import com.google.common.base.MoreObjects;
24
25/**
26 * This Class stores flow specification components and action.
27 */
28public class BgpFlowSpecDetails {
29 private List<BgpValueType> flowSpecComponents;
Shashikanth VHe30cfc42016-02-18 23:31:02 +053030 private List<BgpValueType> fsActionTlv;
Shashikanth VH9bd644a2016-02-11 17:23:49 +053031 private RouteDistinguisher routeDistinguisher;
Shashikanth VHfb391ae2016-02-04 18:15:05 +053032
33 /**
34 * Flow specification details object constructor with the parameter.
35 *
36 * @param flowSpecComponents flow specification components
37 */
38 public BgpFlowSpecDetails(List<BgpValueType> flowSpecComponents) {
39 this.flowSpecComponents = flowSpecComponents;
40 }
41
42 /**
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053043 * Flow specification details object constructor.
44 *
45 */
46 public BgpFlowSpecDetails() {
47
48 }
49
50 /**
Shashikanth VHfb391ae2016-02-04 18:15:05 +053051 * Returns flow specification action tlv.
52 *
53 * @return flow specification action tlv
54 */
Shashikanth VHe30cfc42016-02-18 23:31:02 +053055 public List<BgpValueType> fsActionTlv() {
Shashikanth VHfb391ae2016-02-04 18:15:05 +053056 return this.fsActionTlv;
57 }
58
59 /**
60 * Set flow specification action tlv.
61 *
62 * @param fsActionTlv flow specification action tlv
63 */
Shashikanth VHe30cfc42016-02-18 23:31:02 +053064 public void setFsActionTlv(List<BgpValueType> fsActionTlv) {
Shashikanth VHfb391ae2016-02-04 18:15:05 +053065 this.fsActionTlv = fsActionTlv;
66 }
67
68 /**
69 * Returns route distinguisher for the flow specification components.
70 *
71 * @return route distinguisher for the flow specification components
72 */
73 public RouteDistinguisher routeDistinguisher() {
74 return this.routeDistinguisher;
75 }
76
77 /**
78 * Set route distinguisher for flow specification component.
79 *
80 * @param routeDistinguisher route distinguisher
81 */
82 public void setRouteDistinguiher(RouteDistinguisher routeDistinguisher) {
83 this.routeDistinguisher = routeDistinguisher;
84 }
85
86 /**
87 * Returns flow specification components.
88 *
89 * @return flow specification components
90 */
91 public List<BgpValueType> flowSpecComponents() {
92 return this.flowSpecComponents;
93 }
94
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053095 /**
96 * Sets flow specification components.
97 *
98 * @param flowSpecComponents flow specification components
99 */
100 public void setFlowSpecComponents(List<BgpValueType> flowSpecComponents) {
101 this.flowSpecComponents = flowSpecComponents;
102 }
103
Shashikanth VHfb391ae2016-02-04 18:15:05 +0530104 @Override
105 public int hashCode() {
106 return Objects.hash(flowSpecComponents);
107 }
108
109 @Override
110 public boolean equals(Object obj) {
111 if (this == obj) {
112 return true;
113 }
114
115 if (obj instanceof BgpFlowSpecDetails) {
116 int countObjSubTlv = 0;
117 int countOtherSubTlv = 0;
118 boolean isCommonSubTlv = true;
119 BgpFlowSpecDetails other = (BgpFlowSpecDetails) obj;
120 Iterator<BgpValueType> objListIterator = other.flowSpecComponents.iterator();
121 countOtherSubTlv = other.flowSpecComponents.size();
122 countObjSubTlv = flowSpecComponents.size();
123 if (countObjSubTlv != countOtherSubTlv) {
124 return false;
125 } else {
126 while (objListIterator.hasNext() && isCommonSubTlv) {
127 BgpValueType subTlv = objListIterator.next();
128 if (flowSpecComponents.contains(subTlv) && other.flowSpecComponents.contains(subTlv)) {
129 isCommonSubTlv = Objects.equals(flowSpecComponents.get(flowSpecComponents.indexOf(subTlv)),
130 other.flowSpecComponents.get(other.flowSpecComponents.indexOf(subTlv)));
131 } else {
132 isCommonSubTlv = false;
133 }
134 }
135 return isCommonSubTlv;
136 }
137 }
138 return false;
139 }
140
141 @Override
142 public String toString() {
143 return MoreObjects.toStringHelper(getClass())
144 .add("flowSpecComponents", flowSpecComponents)
145 .toString();
146 }
147}