blob: 6aee0f4945bc38b19d0139432388624a75a40c3e [file] [log] [blame]
Shashikanth VH3fe5f232016-02-09 11:36:15 +05301/*
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 */
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;
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
Shashikanth VH3fe5f232016-02-09 11:36:15 +053080 * @return object of flow spec action traffic marking
81 * @throws BgpParseException while parsing BgpFsActionTrafficMarking
82 */
Shashikanth VH826990b2016-02-11 16:52:46 +053083 public static BgpFsActionTrafficMarking read(ChannelBuffer cb) throws BgpParseException {
84 byte[] dscpValue;
85 ChannelBuffer tempCb = cb.copy();
86
87 dscpValue = tempCb.readBytes(tempCb.readableBytes()).array();
88 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}