blob: cc6384ceab26222370e07e1b7e7d2dfea3481850 [file] [log] [blame]
Shashikanth VHfb391ae2016-02-04 18:15:05 +05301/*
2 * Copyright 2016 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 */
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 VH9bd644a2016-02-11 17:23:49 +053030 private BgpValueType fsActionTlv;
31 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 /**
43 * Returns flow specification action tlv.
44 *
45 * @return flow specification action tlv
46 */
47 public BgpValueType fsActionTlv() {
48 return this.fsActionTlv;
49 }
50
51 /**
52 * Set flow specification action tlv.
53 *
54 * @param fsActionTlv flow specification action tlv
55 */
56 public void setFsActionTlv(BgpValueType fsActionTlv) {
57 this.fsActionTlv = fsActionTlv;
58 }
59
60 /**
61 * Returns route distinguisher for the flow specification components.
62 *
63 * @return route distinguisher for the flow specification components
64 */
65 public RouteDistinguisher routeDistinguisher() {
66 return this.routeDistinguisher;
67 }
68
69 /**
70 * Set route distinguisher for flow specification component.
71 *
72 * @param routeDistinguisher route distinguisher
73 */
74 public void setRouteDistinguiher(RouteDistinguisher routeDistinguisher) {
75 this.routeDistinguisher = routeDistinguisher;
76 }
77
78 /**
79 * Returns flow specification components.
80 *
81 * @return flow specification components
82 */
83 public List<BgpValueType> flowSpecComponents() {
84 return this.flowSpecComponents;
85 }
86
87 @Override
88 public int hashCode() {
89 return Objects.hash(flowSpecComponents);
90 }
91
92 @Override
93 public boolean equals(Object obj) {
94 if (this == obj) {
95 return true;
96 }
97
98 if (obj instanceof BgpFlowSpecDetails) {
99 int countObjSubTlv = 0;
100 int countOtherSubTlv = 0;
101 boolean isCommonSubTlv = true;
102 BgpFlowSpecDetails other = (BgpFlowSpecDetails) obj;
103 Iterator<BgpValueType> objListIterator = other.flowSpecComponents.iterator();
104 countOtherSubTlv = other.flowSpecComponents.size();
105 countObjSubTlv = flowSpecComponents.size();
106 if (countObjSubTlv != countOtherSubTlv) {
107 return false;
108 } else {
109 while (objListIterator.hasNext() && isCommonSubTlv) {
110 BgpValueType subTlv = objListIterator.next();
111 if (flowSpecComponents.contains(subTlv) && other.flowSpecComponents.contains(subTlv)) {
112 isCommonSubTlv = Objects.equals(flowSpecComponents.get(flowSpecComponents.indexOf(subTlv)),
113 other.flowSpecComponents.get(other.flowSpecComponents.indexOf(subTlv)));
114 } else {
115 isCommonSubTlv = false;
116 }
117 }
118 return isCommonSubTlv;
119 }
120 }
121 return false;
122 }
123
124 @Override
125 public String toString() {
126 return MoreObjects.toStringHelper(getClass())
127 .add("flowSpecComponents", flowSpecComponents)
128 .toString();
129 }
130}