blob: 17856c65c0bf820b2a4eeac4dec6086800514e8b [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 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}