blob: 95872523c51f42efec80432268098744b89c97a9 [file] [log] [blame]
Shashikanth VH6fe08ff2016-02-08 16:18:10 +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 BgpFsPortNum implements BgpValueType {
29 public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_PORT;
30 private List<BgpFsOperatorValue> operatorValue;
31
32 /**
33 * Constructor to initialize the value.
34 *
35 * @param operatorValue list of operator and value
36 */
37 public BgpFsPortNum(List<BgpFsOperatorValue> operatorValue) {
38 this.operatorValue = operatorValue;
39 }
40
41 @Override
42 public short getType() {
43 return this.FLOW_SPEC_TYPE;
44 }
45
46 @Override
47 public int hashCode() {
48 return Objects.hash(operatorValue);
49 }
50
51 @Override
52 public boolean equals(Object obj) {
53 if (this == obj) {
54 return true;
55 }
56 if (obj instanceof BgpFsPortNum) {
57 BgpFsPortNum other = (BgpFsPortNum) obj;
58 return this.operatorValue.equals(other.operatorValue);
59 }
60 return false;
61 }
62
63 @Override
64 public int write(ChannelBuffer cb) {
65 int iLenStartIndex = cb.writerIndex();
66
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 port number
83 * @throws BgpParseException while parsing BgpFsPortNum
84 */
85 public static BgpFsPortNum 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}