[ONOS-3857] BGP flow specification component port number TLV
Change-Id: Ie3e9d505b28baef2f351ba42d7c7167a2b046369
diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpFsPortNum.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpFsPortNum.java
new file mode 100755
index 0000000..95872523
--- /dev/null
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpFsPortNum.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types;
+
+import java.util.Objects;
+import java.util.List;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Constants;
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides implementation of BGP flow specification component.
+ */
+public class BgpFsPortNum implements BgpValueType {
+ public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_PORT;
+ private List<BgpFsOperatorValue> operatorValue;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param operatorValue list of operator and value
+ */
+ public BgpFsPortNum(List<BgpFsOperatorValue> operatorValue) {
+ this.operatorValue = operatorValue;
+ }
+
+ @Override
+ public short getType() {
+ return this.FLOW_SPEC_TYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(operatorValue);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof BgpFsPortNum) {
+ BgpFsPortNum other = (BgpFsPortNum) obj;
+ return this.operatorValue.equals(other.operatorValue);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+
+ cb.writeByte(FLOW_SPEC_TYPE);
+
+ for (BgpFsOperatorValue fsOperVal : operatorValue) {
+ cb.writeByte(fsOperVal.option());
+ cb.writeBytes(fsOperVal.value());
+ }
+
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object.
+ *
+ * @param cb channelBuffer
+ * @param type address type
+ * @return object of flow spec port number
+ * @throws BgpParseException while parsing BgpFsPortNum
+ */
+ public static BgpFsPortNum read(ChannelBuffer cb, short type) throws BgpParseException {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("FLOW_SPEC_TYPE", FLOW_SPEC_TYPE)
+ .add("operatorValue", operatorValue).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpFsPortNumTest.java b/protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpFsPortNumTest.java
new file mode 100644
index 0000000..0a98421
--- /dev/null
+++ b/protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpFsPortNumTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.bgpio.types;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Test for BGP flow specification port number component.
+ */
+public class BgpFsPortNumTest {
+ List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>();
+ List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>();
+
+ @Test
+ public void testEquality() {
+ operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100]));
+ operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100]));
+ operatorValue2.add(new BgpFsOperatorValue((byte) 2, new byte[100]));
+ operatorValue2.add(new BgpFsOperatorValue((byte) 1, new byte[100]));
+
+ BgpFsPortNum tlv1 = new BgpFsPortNum(operatorValue1);
+ BgpFsPortNum sameAsTlv1 = new BgpFsPortNum(operatorValue1);
+ BgpFsPortNum tlv2 = new BgpFsPortNum(operatorValue2);
+
+ new EqualsTester()
+ .addEqualityGroup(tlv1, sameAsTlv1)
+ .addEqualityGroup(tlv2)
+ .testEquals();
+ }
+}