Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3856] Implement BGP flow spec RIB out flow specification details.

Change-Id: I9bb65a29c6182009162f1d3d1b7756fa4909240c
1 +/*
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 + */
16 +package org.onosproject.bgpio.protocol.flowspec;
17 +
18 +import java.util.Iterator;
19 +import java.util.List;
20 +import java.util.Objects;
21 +import org.onosproject.bgpio.types.BgpValueType;
22 +import org.onosproject.bgpio.types.RouteDistinguisher;
23 +import com.google.common.base.MoreObjects;
24 +
25 +/**
26 + * This Class stores flow specification components and action.
27 + */
28 +public class BgpFlowSpecDetails {
29 + private List<BgpValueType> flowSpecComponents;
30 + BgpValueType fsActionTlv;
31 + RouteDistinguisher routeDistinguisher;
32 +
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 +}
1 +/*
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 + */
16 +
17 +/**
18 + * BGP Protocol specific flow specification component details.
19 + */
20 +package org.onosproject.bgpio.protocol.flowspec;