blob: 8e78833abb019aac0f98d417927596421ee6724d [file] [log] [blame]
Shashikanth VH3fe5f232016-02-09 11:36:15 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Shashikanth VH3fe5f232016-02-09 11:36:15 +05303 *
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.types;
17
18import java.util.Arrays;
19
20import org.onosproject.bgpio.util.Constants;
21import org.jboss.netty.buffer.ChannelBuffer;
22import org.onosproject.bgpio.exceptions.BgpParseException;
23
24import com.google.common.base.MoreObjects;
25
26/**
27 * Provides implementation of BGP flow specification action.
28 */
29public class BgpFsActionTrafficMarking implements BgpValueType {
30
31 public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING;
32 private byte[] dscpValue;
Shashikanth VH03205d22016-02-19 22:48:08 +053033 public static final byte DSCP_LEN = 6;
Shashikanth VH3fe5f232016-02-09 11:36:15 +053034
35 /**
36 * Constructor to initialize the value.
37 *
38 * @param dscpValue DSCP value
39 */
40 public BgpFsActionTrafficMarking(byte[] dscpValue) {
41 this.dscpValue = Arrays.copyOf(dscpValue, dscpValue.length);
42 }
43
44 @Override
45 public short getType() {
46 return this.TYPE;
47 }
48
49 @Override
50 public int hashCode() {
51 return Arrays.hashCode(dscpValue);
52 }
53
54 @Override
55 public boolean equals(Object obj) {
56 if (this == obj) {
57 return true;
58 }
59 if (obj instanceof BgpFsActionTrafficMarking) {
60 BgpFsActionTrafficMarking other = (BgpFsActionTrafficMarking) obj;
61 return Arrays.equals(this.dscpValue, other.dscpValue);
62 }
63 return false;
64 }
65
66 @Override
67 public int write(ChannelBuffer cb) {
68 int iLenStartIndex = cb.writerIndex();
69
70 cb.writeShort(TYPE);
71
72 cb.writeBytes(dscpValue);
73
74 return cb.writerIndex() - iLenStartIndex;
75 }
76
77 /**
78 * Reads the channel buffer and returns object.
79 *
80 * @param cb channelBuffer
Shashikanth VH3fe5f232016-02-09 11:36:15 +053081 * @return object of flow spec action traffic marking
82 * @throws BgpParseException while parsing BgpFsActionTrafficMarking
83 */
Shashikanth VH826990b2016-02-11 16:52:46 +053084 public static BgpFsActionTrafficMarking read(ChannelBuffer cb) throws BgpParseException {
85 byte[] dscpValue;
Shashikanth VH826990b2016-02-11 16:52:46 +053086
Shashikanth VH03205d22016-02-19 22:48:08 +053087 dscpValue = cb.readBytes(DSCP_LEN).array();
Shashikanth VH826990b2016-02-11 16:52:46 +053088 return new BgpFsActionTrafficMarking(dscpValue);
Shashikanth VH3fe5f232016-02-09 11:36:15 +053089 }
90
91 @Override
92 public String toString() {
93 return MoreObjects.toStringHelper(getClass())
94 .add("TYPE", TYPE)
95 .add("dscpValue", dscpValue).toString();
96 }
97
98 @Override
99 public int compareTo(Object o) {
100 // TODO Auto-generated method stub
101 return 0;
102 }
103}