blob: fef2d3f74457c117191a11f283223c8aca035a7d [file] [log] [blame]
Shashikanth VH60e73982016-02-10 11:25:34 +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.Objects;
19import java.util.List;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.onosproject.bgpio.exceptions.BgpParseException;
22import org.onosproject.bgpio.util.Constants;
23import com.google.common.base.MoreObjects;
24
25/**
26 * Provides implementation of BGP flow specification component.
27 */
28public class BgpFsTcpFlags implements BgpValueType {
29
30 public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_TCP_FLAGS;
31 private List<BgpFsOperatorValue> operatorValue;
32
33 /**
34 * Constructor to initialize the value.
35 *
36 * @param operatorValue list of operator and value
37 */
38 public BgpFsTcpFlags(List<BgpFsOperatorValue> operatorValue) {
39 this.operatorValue = operatorValue;
40 }
41
42 @Override
43 public short getType() {
44 return this.FLOW_SPEC_TYPE;
45 }
46
47 @Override
48 public int hashCode() {
49 return Objects.hash(operatorValue);
50 }
51
52 @Override
53 public boolean equals(Object obj) {
54 if (this == obj) {
55 return true;
56 }
57 if (obj instanceof BgpFsTcpFlags) {
58 BgpFsTcpFlags other = (BgpFsTcpFlags) obj;
59 return this.operatorValue.equals(other.operatorValue);
60 }
61 return false;
62 }
63
64 @Override
65 public int write(ChannelBuffer cb) {
66 int iLenStartIndex = cb.writerIndex();
67 cb.writeByte(FLOW_SPEC_TYPE);
68
69 for (BgpFsOperatorValue fsOperVal : operatorValue) {
70 cb.writeByte(fsOperVal.option());
71 cb.writeBytes(fsOperVal.value());
72 }
73
74 return cb.writerIndex() - iLenStartIndex;
75 }
76
77 /**
78 * Reads the channel buffer and returns object.
79 *
80 * @param cb channelBuffer
81 * @param type address type
82 * @return object of flow spec TCP flags
83 * @throws BgpParseException while parsing BgpFsTcpFlags
84 */
85 public static BgpFsTcpFlags read(ChannelBuffer cb, short type) throws BgpParseException {
86 return null;
87 }
88
89 @Override
90 public String toString() {
91 return MoreObjects.toStringHelper(getClass())
92 .add("FLOW_SPEC_TYPE", FLOW_SPEC_TYPE)
93 .add("operatorValue", operatorValue).toString();
94 }
95
96 @Override
97 public int compareTo(Object o) {
98 // TODO Auto-generated method stub
99 return 0;
100 }
101}