Committed by
Gerrit Code Review
[ONOS-3857] BGP flow specification component port number TLV
Change-Id: Ie3e9d505b28baef2f351ba42d7c7167a2b046369
Showing
2 changed files
with
149 additions
and
0 deletions
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.types; | ||
17 | + | ||
18 | +import java.util.Objects; | ||
19 | +import java.util.List; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
22 | +import org.onosproject.bgpio.util.Constants; | ||
23 | +import com.google.common.base.MoreObjects; | ||
24 | + | ||
25 | +/** | ||
26 | + * Provides implementation of BGP flow specification component. | ||
27 | + */ | ||
28 | +public class BgpFsPortNum implements BgpValueType { | ||
29 | + public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_PORT; | ||
30 | + private List<BgpFsOperatorValue> operatorValue; | ||
31 | + | ||
32 | + /** | ||
33 | + * Constructor to initialize the value. | ||
34 | + * | ||
35 | + * @param operatorValue list of operator and value | ||
36 | + */ | ||
37 | + public BgpFsPortNum(List<BgpFsOperatorValue> operatorValue) { | ||
38 | + this.operatorValue = operatorValue; | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public short getType() { | ||
43 | + return this.FLOW_SPEC_TYPE; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public int hashCode() { | ||
48 | + return Objects.hash(operatorValue); | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public boolean equals(Object obj) { | ||
53 | + if (this == obj) { | ||
54 | + return true; | ||
55 | + } | ||
56 | + if (obj instanceof BgpFsPortNum) { | ||
57 | + BgpFsPortNum other = (BgpFsPortNum) obj; | ||
58 | + return this.operatorValue.equals(other.operatorValue); | ||
59 | + } | ||
60 | + return false; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public int write(ChannelBuffer cb) { | ||
65 | + int iLenStartIndex = cb.writerIndex(); | ||
66 | + | ||
67 | + cb.writeByte(FLOW_SPEC_TYPE); | ||
68 | + | ||
69 | + for (BgpFsOperatorValue fsOperVal : operatorValue) { | ||
70 | + cb.writeByte(fsOperVal.option()); | ||
71 | + cb.writeBytes(fsOperVal.value()); | ||
72 | + } | ||
73 | + | ||
74 | + return cb.writerIndex() - iLenStartIndex; | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Reads the channel buffer and returns object. | ||
79 | + * | ||
80 | + * @param cb channelBuffer | ||
81 | + * @param type address type | ||
82 | + * @return object of flow spec port number | ||
83 | + * @throws BgpParseException while parsing BgpFsPortNum | ||
84 | + */ | ||
85 | + public static BgpFsPortNum read(ChannelBuffer cb, short type) throws BgpParseException { | ||
86 | + return null; | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public String toString() { | ||
91 | + return MoreObjects.toStringHelper(getClass()) | ||
92 | + .add("FLOW_SPEC_TYPE", FLOW_SPEC_TYPE) | ||
93 | + .add("operatorValue", operatorValue).toString(); | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public int compareTo(Object o) { | ||
98 | + // TODO Auto-generated method stub | ||
99 | + return 0; | ||
100 | + } | ||
101 | +} |
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.types; | ||
17 | + | ||
18 | +import java.util.ArrayList; | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +import org.junit.Test; | ||
22 | + | ||
23 | +import com.google.common.testing.EqualsTester; | ||
24 | + | ||
25 | +/** | ||
26 | + * Test for BGP flow specification port number component. | ||
27 | + */ | ||
28 | +public class BgpFsPortNumTest { | ||
29 | + List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>(); | ||
30 | + List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>(); | ||
31 | + | ||
32 | + @Test | ||
33 | + public void testEquality() { | ||
34 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
35 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
36 | + operatorValue2.add(new BgpFsOperatorValue((byte) 2, new byte[100])); | ||
37 | + operatorValue2.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
38 | + | ||
39 | + BgpFsPortNum tlv1 = new BgpFsPortNum(operatorValue1); | ||
40 | + BgpFsPortNum sameAsTlv1 = new BgpFsPortNum(operatorValue1); | ||
41 | + BgpFsPortNum tlv2 = new BgpFsPortNum(operatorValue2); | ||
42 | + | ||
43 | + new EqualsTester() | ||
44 | + .addEqualityGroup(tlv1, sameAsTlv1) | ||
45 | + .addEqualityGroup(tlv2) | ||
46 | + .testEquals(); | ||
47 | + } | ||
48 | +} |
-
Please register or login to post a comment