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