Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3856] Implement BGP flow specication components operator value.

Change-Id: I4262aea2eb0f011d49b424ac34ad675897c07b03
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 +package org.onosproject.bgpio.types;
18 +
19 +import java.util.Arrays;
20 +import java.util.Objects;
21 +import org.slf4j.Logger;
22 +import org.slf4j.LoggerFactory;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +/**
27 + * BGP flow specification type operator and value implementation.
28 + */
29 +public class BgpFsOperatorValue {
30 +
31 + protected static final Logger log = LoggerFactory.getLogger(BgpFsOperatorValue.class);
32 +
33 + private final byte option;
34 + private final byte[] value;
35 +
36 + /**
37 + * constructor to initialize.
38 + *
39 + * @param option for a specific flow type
40 + * @param value for a specific flow type
41 + */
42 + public BgpFsOperatorValue(byte option, byte[] value) {
43 + this.option = option;
44 + this.value = Arrays.copyOf(value, value.length);
45 + }
46 +
47 + /**
48 + * Returns option of the flow type.
49 + *
50 + * @return option of the flow type
51 + */
52 + public byte option() {
53 + return option;
54 + }
55 +
56 + /**
57 + * Returns value of the flow type.
58 + *
59 + * @return value of the flow type
60 + */
61 + public byte[] value() {
62 + return value;
63 + }
64 +
65 + @Override
66 + public int hashCode() {
67 + return Objects.hash(option, Arrays.hashCode(value));
68 + }
69 +
70 + @Override
71 + public boolean equals(Object obj) {
72 + if (this == obj) {
73 + return true;
74 + }
75 + if (obj instanceof BgpFsOperatorValue) {
76 + BgpFsOperatorValue other = (BgpFsOperatorValue) obj;
77 + return Objects.equals(this.option, other.option) && Arrays.equals(this.value, other.value);
78 + }
79 + return false;
80 + }
81 +
82 + @Override
83 + public String toString() {
84 + return MoreObjects.toStringHelper(getClass()).add("option", option).add("value", value).toString();
85 + }
86 +}
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 org.junit.Test;
19 +
20 +import com.google.common.testing.EqualsTester;
21 +
22 +/**
23 + * Test for BgpFsSourcePrefix flow specification component.
24 + */
25 +public class BgpFsOperatorValueTest {
26 + BgpFsOperatorValue tlv1 = new BgpFsOperatorValue((byte) 1, new byte[100]);
27 + BgpFsOperatorValue sameAsTlv1 = new BgpFsOperatorValue((byte) 1, new byte[100]);
28 + BgpFsOperatorValue tlv2 = new BgpFsOperatorValue((byte) 1, new byte[200]);
29 +
30 + @Test
31 + public void testEquality() {
32 + new EqualsTester()
33 + .addEqualityGroup(tlv1, sameAsTlv1)
34 + .addEqualityGroup(tlv2)
35 + .testEquals();
36 + }
37 +}