Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3857] BGP flow specification action components tlv.

Change-Id: I15d8be18aa568520ead48d46dc9ba71e99b658e8
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.Arrays;
19 +
20 +import org.onosproject.bgpio.util.Constants;
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.bgpio.exceptions.BgpParseException;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +/**
27 + * Provides implementation of BGP flow specification action.
28 + */
29 +public class BgpFsActionReDirect implements BgpValueType {
30 +
31 + public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT;
32 + private byte[] routeTarget;
33 +
34 + /**
35 + * Constructor to initialize the value.
36 + *
37 + * @param routeTarget route target
38 + */
39 + public BgpFsActionReDirect(byte[] routeTarget) {
40 + this.routeTarget = Arrays.copyOf(routeTarget, routeTarget.length);
41 + }
42 +
43 + @Override
44 + public short getType() {
45 + return this.TYPE;
46 + }
47 +
48 + @Override
49 + public int hashCode() {
50 + return Arrays.hashCode(routeTarget);
51 + }
52 +
53 + @Override
54 + public boolean equals(Object obj) {
55 + if (this == obj) {
56 + return true;
57 + }
58 + if (obj instanceof BgpFsActionReDirect) {
59 + BgpFsActionReDirect other = (BgpFsActionReDirect) obj;
60 + return Arrays.equals(this.routeTarget, other.routeTarget);
61 + }
62 + return false;
63 + }
64 +
65 + @Override
66 + public int write(ChannelBuffer cb) {
67 + int iLenStartIndex = cb.writerIndex();
68 +
69 + cb.writeShort(TYPE);
70 +
71 + cb.writeBytes(routeTarget);
72 +
73 + return cb.writerIndex() - iLenStartIndex;
74 + }
75 +
76 + /**
77 + * Reads the channel buffer and returns object.
78 + *
79 + * @param cb channelBuffer
80 + * @param type address type
81 + * @return object of flow spec action redirect
82 + * @throws BgpParseException while parsing BgpFsActionReDirect
83 + */
84 + public static BgpFsActionReDirect read(ChannelBuffer cb, short type) throws BgpParseException {
85 + return null;
86 + }
87 +
88 + @Override
89 + public String toString() {
90 + return MoreObjects.toStringHelper(getClass())
91 + .add("TYPE", TYPE)
92 + .add("routeTarget", routeTarget).toString();
93 + }
94 +
95 + @Override
96 + public int compareTo(Object o) {
97 + // TODO Auto-generated method stub
98 + return 0;
99 + }
100 +}
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.Arrays;
19 +
20 +import org.onosproject.bgpio.util.Constants;
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.bgpio.exceptions.BgpParseException;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +/**
27 + * Provides implementation of BGP flow specification action.
28 + */
29 +public class BgpFsActionTrafficAction implements BgpValueType {
30 +
31 + public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION;
32 + private byte[] bitMask;
33 +
34 + /**
35 + * Constructor to initialize the value.
36 + *
37 + * @param bitMask traffic action bit mask
38 + */
39 + public BgpFsActionTrafficAction(byte[] bitMask) {
40 + this.bitMask = Arrays.copyOf(bitMask, bitMask.length);
41 + }
42 +
43 + @Override
44 + public short getType() {
45 + return this.TYPE;
46 + }
47 +
48 + @Override
49 + public int hashCode() {
50 + return Arrays.hashCode(bitMask);
51 + }
52 +
53 + @Override
54 + public boolean equals(Object obj) {
55 + if (this == obj) {
56 + return true;
57 + }
58 + if (obj instanceof BgpFsActionTrafficAction) {
59 + BgpFsActionTrafficAction other = (BgpFsActionTrafficAction) obj;
60 + return Arrays.equals(this.bitMask, other.bitMask);
61 + }
62 + return false;
63 + }
64 +
65 + @Override
66 + public int write(ChannelBuffer cb) {
67 + int iLenStartIndex = cb.writerIndex();
68 +
69 + cb.writeShort(TYPE);
70 +
71 + cb.writeBytes(bitMask);
72 +
73 + return cb.writerIndex() - iLenStartIndex;
74 + }
75 +
76 + /**
77 + * Reads the channel buffer and returns object.
78 + *
79 + * @param cb channelBuffer
80 + * @param type address type
81 + * @return object of flow spec action traffic rate
82 + * @throws BgpParseException while parsing BgpFsActionTrafficAction
83 + */
84 + public static BgpFsActionTrafficAction read(ChannelBuffer cb, short type) throws BgpParseException {
85 + return null;
86 + }
87 +
88 + @Override
89 + public String toString() {
90 + return MoreObjects.toStringHelper(getClass())
91 + .add("TYPE", TYPE)
92 + .add("bitMask", bitMask).toString();
93 + }
94 +
95 + @Override
96 + public int compareTo(Object o) {
97 + // TODO Auto-generated method stub
98 + return 0;
99 + }
100 +}
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.Arrays;
19 +
20 +import org.onosproject.bgpio.util.Constants;
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.bgpio.exceptions.BgpParseException;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +/**
27 + * Provides implementation of BGP flow specification action.
28 + */
29 +public class BgpFsActionTrafficMarking implements BgpValueType {
30 +
31 + public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING;
32 + private byte[] dscpValue;
33 +
34 + /**
35 + * Constructor to initialize the value.
36 + *
37 + * @param dscpValue DSCP value
38 + */
39 + public BgpFsActionTrafficMarking(byte[] dscpValue) {
40 + this.dscpValue = Arrays.copyOf(dscpValue, dscpValue.length);
41 + }
42 +
43 + @Override
44 + public short getType() {
45 + return this.TYPE;
46 + }
47 +
48 + @Override
49 + public int hashCode() {
50 + return Arrays.hashCode(dscpValue);
51 + }
52 +
53 + @Override
54 + public boolean equals(Object obj) {
55 + if (this == obj) {
56 + return true;
57 + }
58 + if (obj instanceof BgpFsActionTrafficMarking) {
59 + BgpFsActionTrafficMarking other = (BgpFsActionTrafficMarking) obj;
60 + return Arrays.equals(this.dscpValue, other.dscpValue);
61 + }
62 + return false;
63 + }
64 +
65 + @Override
66 + public int write(ChannelBuffer cb) {
67 + int iLenStartIndex = cb.writerIndex();
68 +
69 + cb.writeShort(TYPE);
70 +
71 + cb.writeBytes(dscpValue);
72 +
73 + return cb.writerIndex() - iLenStartIndex;
74 + }
75 +
76 + /**
77 + * Reads the channel buffer and returns object.
78 + *
79 + * @param cb channelBuffer
80 + * @param type address type
81 + * @return object of flow spec action traffic marking
82 + * @throws BgpParseException while parsing BgpFsActionTrafficMarking
83 + */
84 + public static BgpFsActionTrafficMarking read(ChannelBuffer cb, short type) throws BgpParseException {
85 + return null;
86 + }
87 +
88 + @Override
89 + public String toString() {
90 + return MoreObjects.toStringHelper(getClass())
91 + .add("TYPE", TYPE)
92 + .add("dscpValue", dscpValue).toString();
93 + }
94 +
95 + @Override
96 + public int compareTo(Object o) {
97 + // TODO Auto-generated method stub
98 + return 0;
99 + }
100 +}
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 org.onosproject.bgpio.util.Constants;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.bgpio.exceptions.BgpParseException;
22 +import com.google.common.base.MoreObjects;
23 +
24 +/**
25 + * Provides implementation of BGP flow specification action.
26 + */
27 +public class BgpFsActionTrafficRate implements BgpValueType {
28 +
29 + public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_RATE;
30 + private short asn;
31 + private float rate;
32 +
33 + /**
34 + * Constructor to initialize the value.
35 + *
36 + * @param asn autonomous system number
37 + * @param rate traffic rate
38 + */
39 + public BgpFsActionTrafficRate(short asn, float rate) {
40 + this.asn = asn;
41 + this.rate = rate;
42 + }
43 +
44 + @Override
45 + public short getType() {
46 + return this.TYPE;
47 + }
48 +
49 + @Override
50 + public int hashCode() {
51 + return Objects.hash(asn, rate);
52 + }
53 +
54 + @Override
55 + public boolean equals(Object obj) {
56 + if (this == obj) {
57 + return true;
58 + }
59 + if (obj instanceof BgpFsActionTrafficRate) {
60 + BgpFsActionTrafficRate other = (BgpFsActionTrafficRate) obj;
61 + return Objects.equals(this.asn, other.asn) && Objects.equals(this.rate, other.rate);
62 + }
63 + return false;
64 + }
65 +
66 + @Override
67 + public int write(ChannelBuffer cb) {
68 +
69 + int iLenStartIndex = cb.writerIndex();
70 + cb.writeShort(TYPE);
71 +
72 + cb.writeShort(asn);
73 +
74 + cb.writeFloat(rate);
75 +
76 + return cb.writerIndex() - iLenStartIndex;
77 + }
78 +
79 + /**
80 + * Reads the channel buffer and returns object.
81 + *
82 + * @param cb channelBuffer
83 + * @param type address type
84 + * @return object of flow spec action traffic rate
85 + * @throws BgpParseException while parsing BgpFsActionTrafficRate
86 + */
87 + public static BgpFsActionTrafficRate read(ChannelBuffer cb, short type) throws BgpParseException {
88 + return null;
89 + }
90 +
91 + @Override
92 + public String toString() {
93 + return MoreObjects.toStringHelper(getClass())
94 + .add("TYPE", TYPE)
95 + .add("asn", asn)
96 + .add("rate", rate).toString();
97 + }
98 +
99 + @Override
100 + public int compareTo(Object o) {
101 + // TODO Auto-generated method stub
102 + return 0;
103 + }
104 +}
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 +import com.google.common.testing.EqualsTester;
20 +
21 +/**
22 + * Test for action redirect flow specification component.
23 + */
24 +public class BgpFsActionReDirectTest {
25 +
26 + private final BgpFsActionReDirect tlv1 = new BgpFsActionReDirect(new byte[100]);
27 + private final BgpFsActionReDirect sameAsTlv1 = new BgpFsActionReDirect(new byte[100]);
28 + private final BgpFsActionReDirect tlv2 = new BgpFsActionReDirect(new byte[200]);
29 +
30 + @Test
31 + public void testEquality() {
32 + new EqualsTester()
33 + .addEqualityGroup(tlv1, sameAsTlv1)
34 + .addEqualityGroup(tlv2)
35 + .testEquals();
36 + }
37 +}
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 +import com.google.common.testing.EqualsTester;
20 +
21 +/**
22 + * Test for traffic action flow specification component.
23 + */
24 +public class BgpFsActionTrafficActionTest {
25 +
26 + private final BgpFsActionTrafficAction tlv1 = new BgpFsActionTrafficAction(new byte[100]);
27 + private final BgpFsActionTrafficAction sameAsTlv1 = new BgpFsActionTrafficAction(new byte[100]);
28 + private final BgpFsActionTrafficAction tlv2 = new BgpFsActionTrafficAction(new byte[200]);
29 +
30 + @Test
31 + public void testEquality() {
32 + new EqualsTester()
33 + .addEqualityGroup(tlv1, sameAsTlv1)
34 + .addEqualityGroup(tlv2)
35 + .testEquals();
36 + }
37 +}
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 +import com.google.common.testing.EqualsTester;
20 +
21 +/**
22 + * Test for action traffic marking flow specification component.
23 + */
24 +public class BgpFsActionTrafficMarkingTest {
25 +
26 + private final BgpFsActionTrafficMarking tlv1 = new BgpFsActionTrafficMarking(new byte[100]);
27 + private final BgpFsActionTrafficMarking sameAsTlv1 = new BgpFsActionTrafficMarking(new byte[100]);
28 + private final BgpFsActionTrafficMarking tlv2 = new BgpFsActionTrafficMarking(new byte[200]);
29 +
30 + @Test
31 + public void testEquality() {
32 + new EqualsTester()
33 + .addEqualityGroup(tlv1, sameAsTlv1)
34 + .addEqualityGroup(tlv2)
35 + .testEquals();
36 + }
37 +}
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 +import com.google.common.testing.EqualsTester;
20 +
21 +/**
22 + * Test for action traffic rate flow specification component.
23 + */
24 +public class BgpFsActionTrafficRateTest {
25 +
26 + private final BgpFsActionTrafficRate tlv1 = new BgpFsActionTrafficRate((short) 1, (float) 1.2);
27 + private final BgpFsActionTrafficRate sameAsTlv1 = new BgpFsActionTrafficRate((short) 1, (float) 1.2);
28 + private final BgpFsActionTrafficRate tlv2 = new BgpFsActionTrafficRate((short) 2, (float) 1.2);
29 +
30 + @Test
31 + public void testEquality() {
32 + new EqualsTester()
33 + .addEqualityGroup(tlv1, sameAsTlv1)
34 + .addEqualityGroup(tlv2)
35 + .testEquals();
36 + }
37 +}