aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types')
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java130
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java175
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java214
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java130
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpErrorType.java74
-rwxr-xr-xframework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpHeader.java161
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpLSIdentifierTlv.java131
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpValueType.java47
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java120
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java165
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java133
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java133
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java124
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java146
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java142
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java314
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java121
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java121
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java225
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java210
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java166
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java139
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java121
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java132
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java168
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java168
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java79
-rwxr-xr-xframework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java199
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java136
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java164
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java135
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java138
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java140
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java143
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java178
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java136
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java156
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java158
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java134
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java139
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java246
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java136
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java138
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java163
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java145
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java204
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java137
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java139
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java193
-rw-r--r--framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java142
-rwxr-xr-xframework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/package-info.java20
-rwxr-xr-xframework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/package-info.java20
52 files changed, 7628 insertions, 0 deletions
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java
new file mode 100644
index 00000000..842c6f02
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AreaIDTlv.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides AreaID Tlv which contains opaque value (32 Bit Area-ID).
+ */
+public class AreaIDTlv implements BgpValueType {
+
+ /* Reference :draft-ietf-idr-ls-distribution-11
+ * 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Type= 514 | Length=4 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | opaque value (32 Bit Area-ID) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+ public static final short TYPE = 514;
+ public static final short LENGTH = 4;
+
+ private final int areaID;
+
+ /**
+ * Constructor to initialize areaID.
+ *
+ * @param areaID of BGP AreaID Tlv
+ */
+ public AreaIDTlv(int areaID) {
+ this.areaID = areaID;
+ }
+
+ /**
+ * Returns object of this class with specified areaID.
+ *
+ * @param areaID opaque value of area id
+ * @return object of AreaIDTlv
+ */
+ public static AreaIDTlv of(final int areaID) {
+ return new AreaIDTlv(areaID);
+ }
+
+ /**
+ * Returns opaque value of area id.
+ *
+ * @return opaque value of area id
+ */
+ public int getAreaID() {
+ return areaID;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(areaID);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof AreaIDTlv) {
+ AreaIDTlv other = (AreaIDTlv) obj;
+ return Objects.equals(areaID, other.areaID);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeInt(areaID);
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of AreaIDTlv.
+ *
+ * @param cb ChannelBuffer
+ * @return object of AreaIDTlv
+ */
+ public static AreaIDTlv read(ChannelBuffer cb) {
+ return AreaIDTlv.of(cb.readInt());
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.areaID)).compareTo((Integer) (((AreaIDTlv) o).areaID));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("Value", areaID)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
new file mode 100644
index 00000000..3ceca2ce
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2015 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 java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of As4Path BGP Path Attribute.
+ */
+public class As4Path implements BgpValueType {
+ private static final Logger log = LoggerFactory.getLogger(AsPath.class);
+ public static final byte AS4PATH_TYPE = 17;
+ public static final byte ASNUM_SIZE = 4;
+
+ private List<Integer> as4pathSet;
+ private List<Integer> as4pathSeq;
+
+ /**
+ * Initialize fields.
+ */
+ public As4Path() {
+ this.as4pathSeq = null;
+ this.as4pathSet = null;
+ }
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param as4pathSet AS4path Set
+ * @param as4pathSeq AS4path Sequence
+ */
+ public As4Path(List<Integer> as4pathSet, List<Integer> as4pathSeq) {
+ this.as4pathSeq = as4pathSeq;
+ this.as4pathSet = as4pathSet;
+ }
+
+ /**
+ * Reads from the channel buffer and parses As4Path.
+ *
+ * @param cb ChannelBuffer
+ * @return object of As4Path
+ * @throws BgpParseException while parsing As4Path
+ */
+ public static As4Path read(ChannelBuffer cb) throws BgpParseException {
+ List<Integer> as4pathSet = new ArrayList<>();
+ List<Integer> as4pathSeq = new ArrayList<>();
+ ChannelBuffer tempCb = cb.copy();
+ Validation validation = Validation.parseAttributeHeader(cb);
+
+ if (cb.readableBytes() < validation.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ validation.getLength());
+ }
+ //if fourth bit is set length is read as short otherwise as byte , len includes type, length and value
+ int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempCb.readBytes(len);
+ if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
+ while (tempBuf.readableBytes() > 0) {
+ byte pathSegType = tempBuf.readByte();
+ //no of ASes
+ byte pathSegLen = tempBuf.readByte();
+ //length = no of Ases * ASnum size (4 bytes)
+ int length = pathSegLen * ASNUM_SIZE;
+ if (tempBuf.readableBytes() < length) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length);
+ }
+ ChannelBuffer aspathBuf = tempBuf.readBytes(length);
+ while (aspathBuf.readableBytes() > 0) {
+ int asNum;
+ asNum = aspathBuf.readInt();
+ switch (pathSegType) {
+ case AsPath.ASPATH_SET_TYPE:
+ as4pathSet.add(asNum);
+ break;
+ case AsPath.ASPATH_SEQ_TYPE:
+ as4pathSeq.add(asNum);
+ break;
+ default: log.debug("Other type Not Supported:" + pathSegType);
+ }
+ }
+ }
+ return new As4Path(as4pathSet, as4pathSeq);
+ }
+
+ @Override
+ public short getType() {
+ return AS4PATH_TYPE;
+ }
+
+ /**
+ * Returns list of ASNum in AS4path Sequence.
+ *
+ * @return list of ASNum in AS4path Sequence
+ */
+ public List<Integer> as4PathSEQ() {
+ return this.as4pathSeq;
+ }
+
+ /**
+ * Returns list of ASNum in AS4path Set.
+ *
+ * @return list of ASNum in AS4path Set
+ */
+ public List<Integer> as4PathSET() {
+ return this.as4pathSet;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(as4pathSet, as4pathSeq);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof As4Path) {
+ As4Path other = (As4Path) obj;
+ return Objects.equals(as4pathSet, other.as4pathSet) && Objects.equals(as4pathSeq, other.as4pathSeq);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("as4pathSet", as4pathSet)
+ .add("as4pathSeq", as4pathSeq)
+ .toString();
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not required to Implement as of now
+ return 0;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
new file mode 100644
index 00000000..2a050c44
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2015 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 java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of AsPath mandatory BGP Path Attribute.
+ */
+public class AsPath implements BgpValueType {
+ /**
+ * Enum to provide AS types.
+ */
+ public enum ASTYPE {
+ AS_SET(1), AS_SEQUENCE(2), AS_CONFED_SEQUENCE(3), AS_CONFED_SET(4);
+ int value;
+
+ /**
+ * Assign val with the value as the AS type.
+ *
+ * @param val AS type
+ */
+ ASTYPE(int val) {
+ value = val;
+ }
+
+ /**
+ * Returns value of AS type.
+ *
+ * @return AS type
+ */
+ public byte type() {
+ return (byte) value;
+ }
+ }
+
+ private static final Logger log = LoggerFactory.getLogger(AsPath.class);
+ public static final byte ASPATH_TYPE = 2;
+ public static final byte ASPATH_SET_TYPE = 1;
+ public static final byte ASPATH_SEQ_TYPE = 2;
+ public static final byte ASNUM_SIZE = 2;
+
+ private boolean isAsPath = false;
+ private List<Short> aspathSet;
+ private List<Short> aspathSeq;
+
+ /**
+ * Initialize Fields.
+ */
+ public AsPath() {
+ this.aspathSeq = null;
+ this.aspathSet = null;
+ }
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param aspathSet ASpath Set type
+ * @param aspathSeq ASpath Sequence type
+ */
+ public AsPath(List<Short> aspathSet, List<Short> aspathSeq) {
+ this.aspathSeq = aspathSeq;
+ this.aspathSet = aspathSet;
+ this.isAsPath = true;
+ }
+
+ /**
+ * Reads from the channel buffer and parses AsPath.
+ *
+ * @param cb ChannelBuffer
+ * @return object of AsPath
+ * @throws BgpParseException while parsing AsPath
+ */
+ public static AsPath read(ChannelBuffer cb) throws BgpParseException {
+ List<Short> aspathSet = new ArrayList<>();
+ List<Short> aspathSeq = new ArrayList<>();
+ ChannelBuffer tempCb = cb.copy();
+ Validation validation = Validation.parseAttributeHeader(cb);
+
+ if (cb.readableBytes() < validation.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ validation.getLength());
+ }
+ //if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value
+ int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempCb.readBytes(len);
+ if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
+ while (tempBuf.readableBytes() > 0) {
+ byte pathSegType = tempBuf.readByte();
+ //no of ASes
+ byte pathSegLen = tempBuf.readByte();
+ int length = pathSegLen * ASNUM_SIZE;
+ if (tempBuf.readableBytes() < length) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length);
+ }
+ ChannelBuffer aspathBuf = tempBuf.readBytes(length);
+ while (aspathBuf.readableBytes() > 0) {
+ short asNum;
+ asNum = aspathBuf.readShort();
+ switch (pathSegType) {
+ case ASPATH_SET_TYPE:
+ aspathSet.add(asNum);
+ break;
+ case ASPATH_SEQ_TYPE:
+ aspathSeq.add(asNum);
+ break;
+ default: log.debug("Other type Not Supported:" + pathSegType);
+ }
+ }
+ }
+ return new AsPath(aspathSet, aspathSeq);
+ }
+
+ @Override
+ public short getType() {
+ return ASPATH_TYPE;
+ }
+
+ /**
+ * Returns whether ASpath path attribute is present.
+ *
+ * @return whether ASpath path attribute is present
+ */
+ public boolean isaspathSet() {
+ return this.isAsPath;
+ }
+
+ /**
+ * Returns list of ASNum in ASpath Sequence.
+ *
+ * @return list of ASNum in ASpath Sequence
+ */
+ public List<Short> asPathSeq() {
+ return this.aspathSeq;
+ }
+
+ /**
+ * Returns list of ASNum in ASpath SET.
+ *
+ * @return list of ASNum in ASpath SET
+ */
+ public List<Short> asPathSet() {
+ return this.aspathSet;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(aspathSet, aspathSeq);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof AsPath) {
+ AsPath other = (AsPath) obj;
+ return Objects.equals(aspathSet, other.aspathSet) && Objects.equals(aspathSeq, other.aspathSeq);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("aspathSet", aspathSet)
+ .add("aspathSeq", aspathSeq)
+ .toString();
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not required to Implement as of now
+ return 0;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java
new file mode 100644
index 00000000..119926c8
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AutonomousSystemTlv.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Autonomous System Tlv which contains opaque value (32 Bit AS Number).
+ */
+public class AutonomousSystemTlv implements BgpValueType {
+
+ /* Reference :draft-ietf-idr-ls-distribution-11
+ * 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Type= 512 | Length=4 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | opaque value (32 Bit AS Number) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+ public static final short TYPE = 512;
+ public static final short LENGTH = 4;
+
+ private final int asNum;
+
+ /**
+ * Constructor to initialize asNum.
+ *
+ * @param asNum 32 Bit AS Number
+ */
+ public AutonomousSystemTlv(int asNum) {
+ this.asNum = asNum;
+ }
+
+ /**
+ * Returns object of this class with specified asNum.
+ *
+ * @param asNum 32 Bit AS Number
+ * @return object of AutonomousSystemTlv
+ */
+ public static AutonomousSystemTlv of(final int asNum) {
+ return new AutonomousSystemTlv(asNum);
+ }
+
+ /**
+ * Returns opaque value of AS Number.
+ *
+ * @return opaque value of AS Number
+ */
+ public int getAsNum() {
+ return asNum;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(asNum);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof AutonomousSystemTlv) {
+ AutonomousSystemTlv other = (AutonomousSystemTlv) obj;
+ return Objects.equals(asNum, other.asNum);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeInt(asNum);
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of AutonomousSystemTlv.
+ *
+ * @param c ChannelBuffer
+ * @return object of AutonomousSystemTlv
+ */
+ public static AutonomousSystemTlv read(ChannelBuffer c) {
+ return AutonomousSystemTlv.of(c.readInt());
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.asNum)).compareTo((Integer) (((AutonomousSystemTlv) o).asNum));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("asNum", asNum)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpErrorType.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpErrorType.java
new file mode 100644
index 00000000..c0932ebe
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpErrorType.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2015 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;
+
+/**
+ * BgpErrorType class defines all errorCodes and error Subcodes required for Notification message.
+ */
+public final class BgpErrorType {
+ private BgpErrorType() {
+ }
+
+ //Error Codes
+ public static final byte MESSAGE_HEADER_ERROR = 1;
+ public static final byte OPEN_MESSAGE_ERROR = 2;
+ public static final byte UPDATE_MESSAGE_ERROR = 3;
+ public static final byte HOLD_TIMER_EXPIRED = 4;
+ public static final byte FINITE_STATE_MACHINE_ERROR = 5;
+ public static final byte CEASE = 6;
+
+ //Message Header Error subcodes
+ public static final byte CONNECTION_NOT_SYNCHRONIZED = 1;
+ public static final byte BAD_MESSAGE_LENGTH = 2;
+ public static final byte BAD_MESSAGE_TYPE = 3;
+
+ //OPEN Message Error subcodes
+ public static final byte UNSUPPORTED_VERSION_NUMBER = 1;
+ public static final byte BAD_PEER_AS = 2;
+ public static final byte BAD_BGP_IDENTIFIER = 3;
+ public static final byte UNSUPPORTED_OPTIONAL_PARAMETER = 4;
+ public static final byte UNACCEPTABLE_HOLD_TIME = 5;
+ public static final byte UNSUPPORTED_CAPABILITY = 7;
+
+ //UPDATE Message Error subcodes
+ public static final byte MALFORMED_ATTRIBUTE_LIST = 1;
+ public static final byte UNRECOGNIZED_WELLKNOWN_ATTRIBUTE = 2;
+ public static final byte MISSING_WELLKNOWN_ATTRIBUTE = 3;
+ public static final byte ATTRIBUTE_FLAGS_ERROR = 4;
+ public static final byte ATTRIBUTE_LENGTH_ERROR = 5;
+ public static final byte INVALID_ORIGIN_ATTRIBUTE = 6;
+ public static final byte INVALID_NEXTHOP_ATTRIBUTE = 8;
+ public static final byte OPTIONAL_ATTRIBUTE_ERROR = 9;
+ public static final byte INVALID_NETWORK_FIELD = 10;
+ public static final byte MALFORMED_ASPATH = 11;
+
+ //FSM Error subcodes
+ public static final byte UNSPECIFIED_ERROR = 0;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE = 1;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE = 2;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_ESTABLISHED_STATE = 3;
+
+ //Cease Error subcodes
+ public static final byte MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1;
+ public static final byte ADMINISTRATIVE_SHUTDOWN = 2;
+ public static final byte PEER_DECONFIGURED = 3;
+ public static final byte ADMINISTRATIVE_RESET = 4;
+ public static final byte CONNECTION_REJECTED = 5;
+ public static final byte OTHER_CONFIGURATION_CHANGE = 6;
+ public static final byte CONNECTION_COLLISION_RESOLUTION = 7;
+ public static final byte OUT_OF_RESOURCES = 8;
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpHeader.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpHeader.java
new file mode 100755
index 00000000..ad637753
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpHeader.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides BGP Message Header which is common for all the Messages.
+ */
+
+public class BgpHeader {
+
+ /* 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ + +
+ | |
+ + +
+ | Marker |
+ + +
+ | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Length | Type |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+ protected static final Logger log = LoggerFactory.getLogger(BgpHeader.class);
+
+ public static final int MARKER_LENGTH = 16;
+ public static final short DEFAULT_HEADER_LENGTH = 19;
+
+ private byte[] marker;
+ private byte type;
+ private short length;
+
+ /**
+ * Reset fields.
+ */
+ public BgpHeader() {
+ this.marker = null;
+ this.length = 0;
+ this.type = 0;
+ }
+
+ /**
+ * Constructors to initialize parameters.
+ *
+ * @param marker field in BGP header
+ * @param length message length
+ * @param type message type
+ */
+ public BgpHeader(byte[] marker, short length, byte type) {
+ this.marker = marker;
+ this.length = length;
+ this.type = type;
+ }
+
+ /**
+ * Sets marker field.
+ *
+ * @param value marker field
+ */
+ public void setMarker(byte[] value) {
+ this.marker = value;
+ }
+
+ /**
+ * Sets message type.
+ *
+ * @param value message type
+ */
+ public void setType(byte value) {
+ this.type = value;
+ }
+
+ /**
+ * Sets message length.
+ *
+ * @param value message length
+ */
+ public void setLength(short value) {
+ this.length = value;
+ }
+
+ /**
+ * Returns message length.
+ *
+ * @return message length
+ */
+ public short getLength() {
+ return this.length;
+ }
+
+ /**
+ * Returns message marker.
+ *
+ * @return message marker
+ */
+ public byte[] getMarker() {
+ return this.marker;
+ }
+
+ /**
+ * Returns message type.
+ *
+ * @return message type
+ */
+ public byte getType() {
+ return this.type;
+ }
+
+ /**
+ * Writes Byte stream of BGP header to channel buffer.
+ *
+ * @param cb ChannelBuffer
+ * @return length index of message header
+ */
+ public int write(ChannelBuffer cb) {
+
+ cb.writeBytes(getMarker(), 0, MARKER_LENGTH);
+
+ int headerLenIndex = cb.writerIndex();
+ cb.writeShort((short) 0);
+ cb.writeByte(type);
+
+ return headerLenIndex;
+ }
+
+ /**
+ * Read from channel buffer and Returns BGP header.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BGPHeader
+ */
+ public static BgpHeader read(ChannelBuffer cb) {
+
+ byte[] marker = new byte[MARKER_LENGTH];
+ byte type;
+ short length;
+ cb.readBytes(marker, 0, MARKER_LENGTH);
+ length = cb.readShort();
+ type = cb.readByte();
+ return new BgpHeader(marker, length, type);
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpLSIdentifierTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpLSIdentifierTlv.java
new file mode 100644
index 00000000..58645d4f
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpLSIdentifierTlv.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides BGPLSIdentifier Tlv which contains opaque value (32 Bit BGPLS-Identifier).
+ */
+public class BgpLSIdentifierTlv implements BgpValueType {
+
+ /* Reference :draft-ietf-idr-ls-distribution-11
+ * 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Type= 513 | Length=4 |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | opaque value (32 Bit BGPLS-Identifier) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+ public static final short TYPE = 513;
+ public static final short LENGTH = 4;
+
+ private final int bgpLsIdentifier;
+
+ /**
+ * Constructor to initialize bgpLsIdentifier.
+ *
+ * @param bgpLsIdentifier BGPLS-Identifier
+ */
+ public BgpLSIdentifierTlv(int bgpLsIdentifier) {
+ this.bgpLsIdentifier = bgpLsIdentifier;
+ }
+
+ /**
+ * Returns object of this class with specified bgpLsIdentifier.
+ *
+ * @param bgpLsIdentifier BGPLS-Identifier
+ * @return BGPLS-Identifier
+ */
+ public static BgpLSIdentifierTlv of(final int bgpLsIdentifier) {
+ return new BgpLSIdentifierTlv(bgpLsIdentifier);
+ }
+
+ /**
+ * Returns opaque value of BGPLS-Identifier.
+ *
+ * @return opaque value of BGPLS-Identifier
+ */
+ public int getBgpLsIdentifier() {
+ return bgpLsIdentifier;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(bgpLsIdentifier);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLSIdentifierTlv) {
+ BgpLSIdentifierTlv other = (BgpLSIdentifierTlv) obj;
+ return Objects.equals(bgpLsIdentifier, other.bgpLsIdentifier);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeInt(bgpLsIdentifier);
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and parses BGPLS Identifier TLV.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BGPLSIdentifierTlv
+ */
+ public static BgpLSIdentifierTlv read(ChannelBuffer cb) {
+ return BgpLSIdentifierTlv.of(cb.readInt());
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.bgpLsIdentifier)).compareTo((Integer) (((BgpLSIdentifierTlv) o).bgpLsIdentifier));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("Value", bgpLsIdentifier)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpValueType.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpValueType.java
new file mode 100644
index 00000000..af7f4b75
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpValueType.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+
+/**
+ * Abstraction which Provides the BGP of TLV format.
+ */
+public interface BgpValueType {
+ /**
+ * Returns the Type of BGP Message.
+ *
+ * @return short value of type
+ */
+ short getType();
+
+ /**
+ * Writes the byte Stream of BGP Message to channel buffer.
+ *
+ * @param cb channel buffer
+ * @return length written to channel buffer
+ */
+ int write(ChannelBuffer cb);
+
+ /**
+ * Compares two objects.
+ *
+ * @param o object
+ * @return result after comparing two objects
+ */
+ int compareTo(Object o);
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java
new file mode 100644
index 00000000..59db3318
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/FourOctetAsNumCapabilityTlv.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides FourOctetAsNumCapabilityTlv Capability Tlv.
+ */
+public class FourOctetAsNumCapabilityTlv implements BgpValueType {
+
+ /**
+ * support to indicate its support for four-octet AS numbers -CAPABILITY TLV format.
+ */
+ protected static final Logger log = LoggerFactory
+ .getLogger(FourOctetAsNumCapabilityTlv.class);
+
+ public static final byte TYPE = 65;
+ public static final byte LENGTH = 4;
+
+ private final int rawValue;
+
+ /**
+ * constructor to initialize rawValue.
+ * @param rawValue FourOctetAsNumCapabilityTlv
+ */
+ public FourOctetAsNumCapabilityTlv(int rawValue) {
+ this.rawValue = rawValue;
+ }
+
+ /**
+ * constructor to initialize raw.
+ * @param raw AS number
+ * @return object of FourOctetAsNumCapabilityTlv
+ */
+ public static FourOctetAsNumCapabilityTlv of(final int raw) {
+ return new FourOctetAsNumCapabilityTlv(raw);
+ }
+
+ /**
+ * Returns value of TLV.
+ * @return int value of rawValue
+ */
+ public int getInt() {
+ return rawValue;
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(rawValue);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof FourOctetAsNumCapabilityTlv) {
+ FourOctetAsNumCapabilityTlv other = (FourOctetAsNumCapabilityTlv) obj;
+ return Objects.equals(rawValue, other.rawValue);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeByte(TYPE);
+ cb.writeByte(LENGTH);
+ cb.writeInt(rawValue);
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of FourOctetAsNumCapabilityTlv.
+ * @param cb type of channel buffer
+ * @return object of FourOctetAsNumCapabilityTlv
+ */
+ public static FourOctetAsNumCapabilityTlv read(ChannelBuffer cb) {
+ return FourOctetAsNumCapabilityTlv.of(cb.readInt());
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("Value", rawValue).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
new file mode 100644
index 00000000..d97537e8
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2015 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.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides IP Reachability InformationTlv Tlv which contains IP Prefix.
+ */
+public class IPReachabilityInformationTlv implements BgpValueType {
+
+ /*
+ * Reference :draft-ietf-idr-ls-distribution-11
+
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Type | Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Prefix Length | IP Prefix (variable) //
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Figure 14: IP Reachability Information TLV Format
+ */
+
+ public static final short TYPE = 265;
+ public static final int ONE_BYTE_LEN = 8;
+
+ private byte prefixLen;
+ private byte[] ipPrefix;
+ public short length;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param prefixLen length of IP Prefix
+ * @param ipPrefix IP Prefix
+ * @param length length of value field
+ */
+ public IPReachabilityInformationTlv(byte prefixLen, byte[] ipPrefix, short length) {
+ this.ipPrefix = ipPrefix;
+ this.prefixLen = prefixLen;
+ this.length = length;
+ }
+
+ /**
+ * Returns IP Prefix.
+ *
+ * @return IP Prefix
+ */
+ public IpPrefix getPrefixValue() {
+ IpPrefix prefix = Validation.bytesToPrefix(ipPrefix, prefixLen);
+ return prefix;
+ }
+
+ /**
+ * Returns IP Prefix length.
+ *
+ * @return IP Prefix length
+ */
+ public byte getPrefixLen() {
+ return this.prefixLen;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(Arrays.hashCode(ipPrefix), prefixLen);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof IPReachabilityInformationTlv) {
+ IPReachabilityInformationTlv other = (IPReachabilityInformationTlv) obj;
+ return Objects.equals(prefixLen, other.prefixLen) && Arrays.equals(ipPrefix, other.ipPrefix);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeShort(TYPE);
+ cb.writeShort(length);
+ cb.writeByte(prefixLen);
+ cb.writeBytes(ipPrefix);
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of IPReachabilityInformationTlv.
+ *
+ * @param cb ChannelBuffer
+ * @param length of value field
+ * @return object of IPReachabilityInformationTlv
+ */
+ public static IPReachabilityInformationTlv read(ChannelBuffer cb, short length) {
+ byte preficLen = cb.readByte();
+ byte[] prefix;
+ if (preficLen == 0) {
+ prefix = new byte[] {0};
+ } else {
+ int len = preficLen / ONE_BYTE_LEN;
+ int reminder = preficLen % ONE_BYTE_LEN;
+ if (reminder > 0) {
+ len = len + 1;
+ }
+ prefix = new byte[len];
+ cb.readBytes(prefix, 0, len);
+ }
+ return IPReachabilityInformationTlv.of(preficLen, prefix, length);
+ }
+
+ public static IPReachabilityInformationTlv of(final byte preficLen, final byte[] prefix, final short length) {
+ return new IPReachabilityInformationTlv(preficLen, prefix, length);
+ }
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix);
+ ByteBuffer value2 = ByteBuffer.wrap(((IPReachabilityInformationTlv) o).ipPrefix);
+ return value1.compareTo(value2);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", length)
+ .add("Prefixlength", getPrefixLen())
+ .add("Prefixvalue", getPrefixValue())
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java
new file mode 100644
index 00000000..4efde70e
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2015 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.net.InetAddress;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+/**
+ * Provides Implementation of IPv4AddressTlv.
+ */
+public class IPv4AddressTlv implements BgpValueType {
+ private static final int LENGTH = 4;
+
+ private Ip4Address address;
+ private short type;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param address Ipv4 address of interface/neighbor
+ * @param type address type
+ */
+ public IPv4AddressTlv(Ip4Address address, short type) {
+ this.address = Preconditions.checkNotNull(address);
+ this.type = type;
+ }
+
+ /**
+ * Returns Ipv4 address of interface/neighbor.
+ *
+ * @return Ipv4 address of interface/neighbor
+ */
+ public Ip4Address address() {
+ return address;
+ }
+
+ @Override
+ public short getType() {
+ return this.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof IPv4AddressTlv) {
+ IPv4AddressTlv other = (IPv4AddressTlv) obj;
+ return Objects.equals(this.address, other.address) && Objects.equals(this.type, other.type);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeShort(type);
+ cb.writeShort(LENGTH);
+ cb.writeInt(address.toInt());
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of IPv4AddressTlv.
+ *
+ * @param cb channelBuffer
+ * @param type address type
+ * @return object of IPv4AddressTlv
+ * @throws BgpParseException while parsing IPv4AddressTlv
+ */
+ public static IPv4AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
+ InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
+ if (ipAddress.isMulticastAddress()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ }
+ Ip4Address address = Ip4Address.valueOf(ipAddress);
+ return IPv4AddressTlv.of(address, type);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param address Ipv4 interface/neighbor Address
+ * @param type says Ipv4 address of interface/neighbor tlv type
+ * @return object of this class
+ */
+ public static IPv4AddressTlv of(final Ip4Address address , final short type) {
+ return new IPv4AddressTlv(address, type);
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Ip4Address) (this.address)).compareTo((Ip4Address) (((IPv4AddressTlv) o).address));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("type", type)
+ .add("LENGTH", LENGTH)
+ .add("address", address)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java
new file mode 100644
index 00000000..087cd5c6
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2015 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.net.InetAddress;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip6Address;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+/**
+ * Provides Implementation of IPv6AddressTlv.
+ */
+public class IPv6AddressTlv implements BgpValueType {
+ private static final int LENGTH = 16;
+
+ private final Ip6Address address;
+ private short type;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param address Ipv6 address of interface/neighbor
+ * @param type address type
+ */
+ public IPv6AddressTlv(Ip6Address address, short type) {
+ this.address = Preconditions.checkNotNull(address);
+ this.type = type;
+ }
+
+ /**
+ * Returns Ipv6 address of interface/neighbor.
+ *
+ * @return Ipv6 address of interface/neighbor
+ */
+ public Ip6Address address() {
+ return address;
+ }
+
+ @Override
+ public short getType() {
+ return type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(address);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof IPv6AddressTlv) {
+ IPv6AddressTlv other = (IPv6AddressTlv) obj;
+ return Objects.equals(this.address, other.address) && Objects.equals(this.type, other.type);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeShort(type);
+ cb.writeShort(LENGTH);
+ cb.writeBytes(address.toOctets());
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of IPv6AddressTlv.
+ *
+ * @param cb channelBuffer
+ * @param type address type
+ * @return object of IPv6AddressTlv
+ * @throws BgpParseException while parsing IPv6AddressTlv
+ */
+ public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
+ InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
+ if (ipAddress.isMulticastAddress()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ }
+ Ip6Address address = Ip6Address.valueOf(ipAddress);
+ return IPv6AddressTlv.of(address, type);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param address Ipv6 interface/neighbor address
+ * @param type says Ipv6 address of interface/neighbor tlv type
+ * @return object of this class
+ */
+ public static IPv6AddressTlv of(final Ip6Address address , final short type) {
+ return new IPv6AddressTlv(address, type);
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Ip6Address) (this.address)).compareTo((Ip6Address) (((IPv6AddressTlv) o).address));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("type", type)
+ .add("LENGTH", LENGTH)
+ .add("address", address)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
new file mode 100644
index 00000000..427aa929
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsNonPseudonode.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2015 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.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.protocol.IGPRouterID;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of IsIsNonPseudonode Tlv.
+ */
+public class IsIsNonPseudonode implements IGPRouterID, BgpValueType {
+ public static final short TYPE = 515;
+ public static final short LENGTH = 6;
+
+ private final byte[] isoNodeID;
+
+ /**
+ * Constructor to initialize isoNodeID.
+ *
+ * @param isoNodeID ISO system-ID
+ */
+ public IsIsNonPseudonode(byte[] isoNodeID) {
+ this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
+ }
+
+ /**
+ * Returns object of this class with specified isoNodeID.
+ *
+ * @param isoNodeID ISO system-ID
+ * @return object of IsIsNonPseudonode
+ */
+ public static IsIsNonPseudonode of(final byte[] isoNodeID) {
+ return new IsIsNonPseudonode(isoNodeID);
+ }
+
+ /**
+ * Returns ISO NodeID.
+ *
+ * @return ISO NodeID
+ */
+ public byte[] getISONodeID() {
+ return isoNodeID;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(isoNodeID);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof IsIsNonPseudonode) {
+ IsIsNonPseudonode other = (IsIsNonPseudonode) obj;
+ return Arrays.equals(isoNodeID, other.isoNodeID);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeBytes(isoNodeID);
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of IsIsNonPseudonode.
+ *
+ * @param cb ChannelBuffer
+ * @return object of IsIsNonPseudonode
+ */
+ public static IsIsNonPseudonode read(ChannelBuffer cb) {
+ byte[] isoNodeID = new byte[LENGTH];
+ cb.readBytes(isoNodeID);
+ return IsIsNonPseudonode.of(isoNodeID);
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
+ ByteBuffer value2 = ByteBuffer.wrap(((IsIsNonPseudonode) o).isoNodeID);
+ return value1.compareTo(value2);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("ISONodeID", isoNodeID)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
new file mode 100644
index 00000000..094c4382
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2015 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.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.protocol.IGPRouterID;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides implementation of IsIsPseudonode Tlv.
+ */
+public class IsIsPseudonode implements IGPRouterID, BgpValueType {
+ public static final short TYPE = 515;
+ public static final short LENGTH = 7;
+
+ private final byte[] isoNodeID;
+ private byte psnIdentifier;
+
+ /**
+ * Constructor to initialize isoNodeID.
+ *
+ * @param isoNodeID ISO system-ID
+ * @param psnIdentifier PSN identifier
+ */
+ public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) {
+ this.isoNodeID = Arrays.copyOf(isoNodeID, isoNodeID.length);
+ this.psnIdentifier = psnIdentifier;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param isoNodeID ISO system-ID
+ * @param psnIdentifier PSN identifier
+ * @return object of IsIsPseudonode
+ */
+ public static IsIsPseudonode of(final byte[] isoNodeID,
+ final byte psnIdentifier) {
+ return new IsIsPseudonode(isoNodeID, psnIdentifier);
+ }
+
+ /**
+ * Returns ISO NodeID.
+ *
+ * @return ISO NodeID
+ */
+ public byte[] getISONodeID() {
+ return isoNodeID;
+ }
+
+ /**
+ * Returns PSN Identifier.
+ *
+ * @return PSN Identifier
+ */
+ public byte getPSNIdentifier() {
+ return this.psnIdentifier;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(isoNodeID) & Objects.hash(psnIdentifier);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof IsIsPseudonode) {
+ IsIsPseudonode other = (IsIsPseudonode) obj;
+ return Arrays.equals(isoNodeID, other.isoNodeID)
+ && Objects.equals(psnIdentifier, other.psnIdentifier);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeBytes(isoNodeID, 0, LENGTH - 1);
+ c.writeByte(psnIdentifier);
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of IsIsPseudonode.
+ *
+ * @param cb ChannelBuffer
+ * @return object of IsIsPseudonode
+ */
+ public static IsIsPseudonode read(ChannelBuffer cb) {
+ byte[] isoNodeID = new byte[LENGTH - 1];
+ cb.readBytes(isoNodeID);
+ byte psnIdentifier = cb.readByte();
+ return IsIsPseudonode.of(isoNodeID, psnIdentifier);
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ ByteBuffer value1 = ByteBuffer.wrap(this.isoNodeID);
+ ByteBuffer value2 = ByteBuffer.wrap(((IsIsPseudonode) o).isoNodeID);
+ if (value1.compareTo(value2) != 0) {
+ return value1.compareTo(value2);
+ }
+ return ((Byte) (this.psnIdentifier)).compareTo((Byte) (((IsIsPseudonode) o).psnIdentifier));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("isoNodeID", isoNodeID)
+ .add("psnIdentifier", psnIdentifier)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java
new file mode 100644
index 00000000..0c412432
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of Link Local/Remote IdentifiersTlv.
+ */
+public class LinkLocalRemoteIdentifiersTlv implements BgpValueType {
+ public static final short TYPE = 258;
+ private static final int LENGTH = 8;
+
+ private final int linkLocalIdentifer;
+ private final int linkRemoteIdentifer;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param linkLocalIdentifer link local Identifer
+ * @param linkRemoteIdentifer link remote Identifer
+ */
+ public LinkLocalRemoteIdentifiersTlv(int linkLocalIdentifer, int linkRemoteIdentifer) {
+ this.linkLocalIdentifer = linkLocalIdentifer;
+ this.linkRemoteIdentifer = linkRemoteIdentifer;
+ }
+
+ /**
+ * Returns link remote Identifer.
+ *
+ * @return link remote Identifer
+ */
+ public int getLinkRemoteIdentifier() {
+ return linkRemoteIdentifer;
+ }
+
+ /**
+ * Returns link local Identifer.
+ *
+ * @return link local Identifer
+ */
+ public int getLinkLocalIdentifier() {
+ return linkLocalIdentifer;
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(linkLocalIdentifer, linkRemoteIdentifer);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof LinkLocalRemoteIdentifiersTlv) {
+ LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj;
+ return Objects.equals(this.linkLocalIdentifer, other.linkLocalIdentifer)
+ && Objects.equals(this.linkRemoteIdentifer, other.linkRemoteIdentifer);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeShort(TYPE);
+ cb.writeShort(LENGTH);
+ cb.writeInt(linkLocalIdentifer);
+ cb.writeInt(linkRemoteIdentifer);
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
+ *
+ * @param cb channelBuffer
+ * @return object of LinkLocalRemoteIdentifiersTlv
+ */
+ public static LinkLocalRemoteIdentifiersTlv read(ChannelBuffer cb) {
+ int linkLocalIdentifer = cb.readInt();
+ int linkRemoteIdentifer = cb.readInt();
+ return LinkLocalRemoteIdentifiersTlv.of(linkLocalIdentifer, linkRemoteIdentifer);
+ }
+
+ /**
+ * Returns object of this class with specified link local identifer and link remote identifer.
+ *
+ * @param linkLocalIdentifer link local identifier
+ * @param linkRemoteIdentifer link remote identifier
+ * @return object of LinkLocalRemoteIdentifiersTlv
+ */
+ public static LinkLocalRemoteIdentifiersTlv of(final int linkLocalIdentifer, final int linkRemoteIdentifer) {
+ return new LinkLocalRemoteIdentifiersTlv(linkLocalIdentifer, linkRemoteIdentifer);
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int result = ((Integer) (this.linkLocalIdentifer))
+ .compareTo((Integer) (((LinkLocalRemoteIdentifiersTlv) o).linkLocalIdentifer));
+ if (result != 0) {
+ return result;
+ }
+ return ((Integer) (this.linkRemoteIdentifer))
+ .compareTo((Integer) (((LinkLocalRemoteIdentifiersTlv) o).linkRemoteIdentifer));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("TYPE", TYPE)
+ .add("LENGTH", LENGTH)
+ .add("linkLocalIdentifer", linkLocalIdentifer)
+ .add("linkRemoteIdentifer", linkRemoteIdentifer)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java
new file mode 100644
index 00000000..cdf6ebeb
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkStateAttributes.java
@@ -0,0 +1,314 @@
+/*
+ * Copyright 2015 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.LinkedList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeIsIsAreaId;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId;
+import org.onosproject.bgpio.types.attr.BgpAttrNodeName;
+import org.onosproject.bgpio.types.attr.BgpAttrOpaqueNode;
+import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4;
+import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV6;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrIsIsAdminstGrp;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrMplsProtocolMask;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrName;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrOpaqLnkAttrib;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrProtectionType;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrSrlg;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric;
+import org.onosproject.bgpio.types.attr.BgpLinkAttrUnRsrvdLinkBandwidth;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrExtRouteTag;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrMetric;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrOspfFwdAddr;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrOpaqueData;
+import org.onosproject.bgpio.types.attr.BgpPrefixAttrRouteTag;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP Link state attribute.
+ */
+public class LinkStateAttributes implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(LinkStateAttributes.class);
+
+ /* Node Attributes */
+ public static final short ATTR_NODE_MT_TOPOLOGY_ID = 263;
+ public static final short ATTR_NODE_FLAG_BITS = 1024;
+ public static final short ATTR_NODE_OPAQUE_NODE = 1025;
+ public static final short ATTR_NODE_NAME = 1026;
+ public static final short ATTR_NODE_ISIS_AREA_ID = 1027;
+ public static final short ATTR_NODE_IPV4_LOCAL_ROUTER_ID = 1028;
+ public static final short ATTR_NODE_IPV6_LOCAL_ROUTER_ID = 1029;
+
+ /* Link Attributes */
+ public static final short ATTR_LINK_IPV4_REMOTE_ROUTER_ID = 1030;
+ public static final short ATTR_LINK_IPV6_REMOTE_ROUTER_ID = 1031;
+ public static final short ATTR_LINK_ADMINISTRATIVE_GRPS = 1088;
+ public static final short ATTR_LINK_MAX_BANDWIDTH = 1089;
+ public static final short ATTR_LINK_MAX_RES_BANDWIDTH = 1090;
+ public static final short ATTR_LINK_UNRES_BANDWIDTH = 1091;
+ public static final short ATTR_LINK_TE_DEFAULT_METRIC = 1092;
+ public static final short ATTR_LINK_PROTECTION_TYPE = 1093;
+ public static final short ATTR_LINK_MPLS_PROTOCOL_MASK = 1094;
+ public static final short ATTR_LINK_IGP_METRIC = 1095;
+ public static final short ATTR_LINK_SHR_RISK_GRP = 1096;
+ public static final short ATTR_LINK_OPAQUE_ATTR = 1097;
+ public static final short ATTR_LINK_NAME_ATTR = 1098;
+
+ /* Prefix Attributes */
+ public static final short ATTR_PREFIX_IGP_FLAG = 1152;
+ public static final short ATTR_PREFIX_ROUTE_TAG = 1153;
+ public static final short ATTR_PREFIX_EXTENDED_TAG = 1154;
+ public static final short ATTR_PREFIX_METRIC = 1155;
+ public static final short ATTR_PREFIX_OSPF_FWD_ADDR = 1156;
+ public static final short ATTR_PREFIX_OPAQUE_ATTR = 1157;
+
+ public static final byte LINKSTATE_ATTRIB_TYPE = 50;
+ public static final byte TYPE_AND_LEN = 4;
+ private boolean isLinkStateAttribute = false;
+ private List<BgpValueType> linkStateAttribList;
+
+ /**
+ * Constructor to reset parameters.
+ */
+ LinkStateAttributes() {
+ this.linkStateAttribList = null;
+ }
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param linkStateAttribList Linked list of Link, Node and Prefix TLVs
+ */
+ LinkStateAttributes(List<BgpValueType> linkStateAttribList) {
+ this.linkStateAttribList = linkStateAttribList;
+ this.isLinkStateAttribute = true;
+ }
+
+ /**
+ * Returns linked list of Link, Node and Prefix TLVs.
+ *
+ * @return linked list of Link, Node and Prefix TLVs
+ */
+ public List<BgpValueType> linkStateAttributes() {
+ return this.linkStateAttribList;
+ }
+
+ /**
+ * Returns if the Link state attributes are set or not.
+ *
+ * @return a boolean value to to check if the LS attributes are set or not
+ */
+ public boolean isLinkStateAttributeSet() {
+ return this.isLinkStateAttribute;
+ }
+
+ /**
+ * Reads the Link state attribute TLVs.
+ *
+ * @param cb ChannelBuffer
+ * @return constructor of LinkStateAttributes
+ * @throws BgpParseException while parsing link state attributes
+ */
+ public static LinkStateAttributes read(ChannelBuffer cb)
+ throws BgpParseException {
+
+ ChannelBuffer tempBuf = cb;
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+ int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN
+ : parseFlags.getLength() + 3;
+
+ ChannelBuffer data = tempBuf.readBytes(len);
+ if (!parseFlags.getFirstBit() || parseFlags.getSecondBit()
+ || parseFlags.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_FLAGS_ERROR,
+ data);
+ }
+
+ if (cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.BAD_MESSAGE_LENGTH,
+ parseFlags.getLength());
+ }
+
+ BgpValueType bgpLSAttrib = null;
+ LinkedList<BgpValueType> linkStateAttribList;
+ linkStateAttribList = new LinkedList<BgpValueType>();
+ ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
+ while (tempCb.readableBytes() > 0) {
+ short tlvCodePoint = tempCb.readShort();
+ switch (tlvCodePoint) {
+
+ /********* 7 NODE ATTRIBUTES ********/
+ case ATTR_NODE_MT_TOPOLOGY_ID: /* 263 Multi-Topology Identifier*/
+ bgpLSAttrib = BgpAttrNodeMultiTopologyId.read(tempCb);
+ break;
+
+ case ATTR_NODE_FLAG_BITS: /*Node flag bit TLV*/
+ bgpLSAttrib = BgpAttrNodeFlagBitTlv.read(tempCb);
+ break;
+
+ case ATTR_NODE_OPAQUE_NODE: /*Opaque Node Attribute*/
+ bgpLSAttrib = BgpAttrOpaqueNode.read(tempCb);
+ break;
+
+ case ATTR_NODE_NAME: /*Node Name*/
+ bgpLSAttrib = BgpAttrNodeName.read(tempCb);
+ break;
+
+ case ATTR_NODE_ISIS_AREA_ID: /*IS-IS Area Identifier TLV*/
+ bgpLSAttrib = BgpAttrNodeIsIsAreaId.read(tempCb);
+ break;
+
+ case ATTR_NODE_IPV4_LOCAL_ROUTER_ID: /*IPv4 Router-ID of Local Node*/
+ bgpLSAttrib = BgpAttrRouterIdV4.read(tempCb, (short) ATTR_NODE_IPV4_LOCAL_ROUTER_ID);
+ break;
+
+ case ATTR_NODE_IPV6_LOCAL_ROUTER_ID: /*IPv6 Router-ID of Local Node*/
+ bgpLSAttrib = BgpAttrRouterIdV6.read(tempCb, (short) ATTR_NODE_IPV6_LOCAL_ROUTER_ID);
+ break;
+
+ /********* 15 LINK ATTRIBUTES ********/
+
+ case ATTR_LINK_IPV4_REMOTE_ROUTER_ID: /*IPv4 Router-ID of Remote Node*/
+ bgpLSAttrib = BgpAttrRouterIdV4.read(tempCb, (short) 1030);
+ break;
+
+ case ATTR_LINK_IPV6_REMOTE_ROUTER_ID: /*IPv6 Router-ID of Remote Node*/
+ bgpLSAttrib = BgpAttrRouterIdV6.read(tempCb, (short) 1031);
+ break;
+
+ case ATTR_LINK_ADMINISTRATIVE_GRPS: /*ISIS Administrative group STLV 3*/
+ bgpLSAttrib = BgpLinkAttrIsIsAdminstGrp.read(tempCb);
+ break;
+
+ case ATTR_LINK_MAX_BANDWIDTH: /*Maximum link bandwidth*/
+ bgpLSAttrib = BgpLinkAttrMaxLinkBandwidth.read(tempCb,
+ (short) 1089);
+ break;
+
+ case ATTR_LINK_MAX_RES_BANDWIDTH: /* Maximum Reservable link bandwidth */
+ bgpLSAttrib = BgpLinkAttrMaxLinkBandwidth.read(tempCb,
+ (short) 1090);
+ break;
+
+ case ATTR_LINK_UNRES_BANDWIDTH: /* UnReserved link bandwidth */
+ bgpLSAttrib = BgpLinkAttrUnRsrvdLinkBandwidth
+ .read(tempCb, (short) 1091);
+ break;
+
+ case ATTR_LINK_TE_DEFAULT_METRIC: /* TE Default Metric */
+ bgpLSAttrib = BgpLinkAttrTeDefaultMetric.read(tempCb);
+ break;
+
+ case ATTR_LINK_PROTECTION_TYPE:/* Link Protection type */
+ bgpLSAttrib = BgpLinkAttrProtectionType.read(tempCb);
+ break;
+
+ case ATTR_LINK_MPLS_PROTOCOL_MASK: /* MPLS Protocol Mask */
+ bgpLSAttrib = BgpLinkAttrMplsProtocolMask.read(tempCb); // 2
+ break;
+
+ case ATTR_LINK_IGP_METRIC: /* IGP Metric */
+ bgpLSAttrib = BgpLinkAttrIgpMetric.read(tempCb); // 2
+ break;
+
+ case ATTR_LINK_SHR_RISK_GRP: /* Shared Risk Link Group */
+ bgpLSAttrib = BgpLinkAttrSrlg.read(tempCb); // 3
+ break;
+
+ case ATTR_LINK_OPAQUE_ATTR: /* Opaque link attribute */
+ bgpLSAttrib = BgpLinkAttrOpaqLnkAttrib.read(tempCb);
+ break;
+
+ case ATTR_LINK_NAME_ATTR: /* Link Name attribute */
+ bgpLSAttrib = BgpLinkAttrName.read(tempCb);
+ break;
+
+ /********* 6 PREFIX ATTRIBUTES ********/
+
+ case ATTR_PREFIX_IGP_FLAG: /* IGP Flags */
+ bgpLSAttrib = BgpPrefixAttrIgpFlags.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_ROUTE_TAG: /* Route Tag */
+ bgpLSAttrib = BgpPrefixAttrRouteTag.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_EXTENDED_TAG: /* Extended Tag */
+ bgpLSAttrib = BgpPrefixAttrExtRouteTag.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_METRIC: /* Prefix Metric */
+ bgpLSAttrib = BgpPrefixAttrMetric.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_OSPF_FWD_ADDR: /* OSPF Forwarding Address */
+ bgpLSAttrib = BgpPrefixAttrOspfFwdAddr.read(tempCb);
+ break;
+
+ case ATTR_PREFIX_OPAQUE_ATTR: /* Opaque Prefix Attribute */
+ bgpLSAttrib = BgpPrefixAttrOpaqueData.read(tempCb);
+ break;
+
+ default:
+ throw new BgpParseException(
+ "The Bgp-LS Attribute is not supported : "
+ + tlvCodePoint);
+ }
+
+ linkStateAttribList.add(bgpLSAttrib);
+ }
+ return new LinkStateAttributes(linkStateAttribList);
+ }
+
+ @Override
+ public short getType() {
+ return LINKSTATE_ATTRIB_TYPE;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("linkStateAttribList", linkStateAttribList).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
new file mode 100644
index 00000000..36793c18
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides implementation of LocalPref BGP Path Attribute.
+ */
+public class LocalPref implements BgpValueType {
+ public static final byte LOCAL_PREF_TYPE = 5;
+ public static final byte LOCAL_PREF_MAX_LEN = 4;
+
+ private int localPref;
+
+ /**
+ * Constructor to initialize LocalPref.
+ *
+ * @param localPref local preference
+ */
+ public LocalPref(int localPref) {
+ this.localPref = localPref;
+ }
+
+ /**
+ * Returns local preference value.
+ *
+ * @return local preference value
+ */
+ public int localPref() {
+ return this.localPref;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of LocalPref.
+ *
+ * @param cb channelBuffer
+ * @return object of LocalPref
+ * @throws BgpParseException while parsing localPref attribute
+ */
+ public static LocalPref read(ChannelBuffer cb) throws BgpParseException {
+ int localPref;
+ ChannelBuffer tempCb = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+ if ((parseFlags.getLength() > LOCAL_PREF_MAX_LEN) || cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ parseFlags.getLength());
+ }
+
+ int len = parseFlags.isShort() ? parseFlags.getLength() +
+ Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempCb.readBytes(len);
+ if (parseFlags.getFirstBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ localPref = cb.readInt();
+ return new LocalPref(localPref);
+ }
+
+ @Override
+ public short getType() {
+ return LOCAL_PREF_TYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(localPref);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof LocalPref) {
+ LocalPref other = (LocalPref) obj;
+ return Objects.equals(localPref, other.localPref);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("localPref", localPref)
+ .toString();
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not to implement as of now
+ return 0;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
new file mode 100644
index 00000000..7f1ab53f
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of Med BGP Path Attribute.
+ */
+public class Med implements BgpValueType {
+ public static final byte MED_TYPE = 4;
+ public static final byte MED_MAX_LEN = 4;
+
+ private int med;
+
+ /**
+ * Constructor to initialize med.
+ *
+ * @param med MULTI_EXIT_DISC value
+ */
+ public Med(int med) {
+ this.med = med;
+ }
+
+ /**
+ * Returns Med value.
+ *
+ * @return Med value
+ */
+ public int med() {
+ return this.med;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of Med.
+ *
+ * @param cb ChannelBuffer
+ * @return object of Med
+ * @throws BgpParseException while parsing Med path attribute
+ */
+ public static Med read(ChannelBuffer cb) throws BgpParseException {
+ int med;
+ ChannelBuffer tempCb = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+
+ if ((parseFlags.getLength() > MED_MAX_LEN) || cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ parseFlags.getLength());
+ }
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempCb.readBytes(len);
+ if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ med = cb.readInt();
+ return new Med(med);
+ }
+
+ @Override
+ public short getType() {
+ return MED_TYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(med);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof Med) {
+ Med other = (Med) obj;
+ return Objects.equals(med, other.med);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("med", med)
+ .toString();
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not to implement as of now
+ return 0;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
new file mode 100644
index 00000000..2e4e6599
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
@@ -0,0 +1,225 @@
+/*
+ * Copyright 2015 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.net.InetAddress;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/*
+ * Provides Implementation of MpReach Nlri BGP Path Attribute.
+ */
+public class MpReachNlri implements BgpValueType {
+
+ private static final Logger log = LoggerFactory.getLogger(MpReachNlri.class);
+ public static final byte MPREACHNLRI_TYPE = 14;
+ public static final byte LINK_NLRITYPE = 2;
+
+ private boolean isMpReachNlri = false;
+ private final List<BgpLSNlri> mpReachNlri;
+ private final int length;
+ private final short afi;
+ private final byte safi;
+ private final Ip4Address ipNextHop;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param mpReachNlri MpReach Nlri attribute
+ * @param afi address family identifier
+ * @param safi subsequent address family identifier
+ * @param ipNextHop nexthop IpAddress
+ * @param length of MpReachNlri
+ */
+ public MpReachNlri(List<BgpLSNlri> mpReachNlri, short afi, byte safi, Ip4Address ipNextHop, int length) {
+ this.mpReachNlri = mpReachNlri;
+ this.isMpReachNlri = true;
+ this.ipNextHop = ipNextHop;
+ this.afi = afi;
+ this.safi = safi;
+ this.length = length;
+ }
+
+ /**
+ * Returns whether MpReachNlri is present.
+ *
+ * @return whether MpReachNlri is present
+ */
+ public boolean isMpReachNlriSet() {
+ return this.isMpReachNlri;
+ }
+
+ /**
+ * Returns list of MpReach Nlri.
+ *
+ * @return list of MpReach Nlri
+ */
+ public List<BgpLSNlri> mpReachNlri() {
+ return this.mpReachNlri;
+ }
+
+ /**
+ * Returns length of MpReachNlri.
+ *
+ * @return length of MpReachNlri
+ */
+ public int mpReachNlriLen() {
+ return this.length;
+ }
+
+ /**
+ * Reads from ChannelBuffer and parses MpReachNlri.
+ *
+ * @param cb channelBuffer
+ * @return object of MpReachNlri
+ * @throws BgpParseException while parsing MpReachNlri
+ */
+ public static MpReachNlri read(ChannelBuffer cb) throws BgpParseException {
+ ChannelBuffer tempBuf = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT :
+ parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempBuf.readBytes(len);
+
+ if (cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ parseFlags.getLength());
+ }
+ if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ BgpLSNlri bgpLSNlri = null;
+ List<BgpLSNlri> mpReachNlri = new LinkedList<>();
+ ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
+ short afi = 0;
+ byte safi = 0;
+ Ip4Address ipNextHop = null;
+ while (tempCb.readableBytes() > 0) {
+ afi = tempCb.readShort();
+ safi = tempCb.readByte();
+
+ //Supporting for AFI 16388 / SAFI 71 and VPN AFI 16388 / SAFI 128
+ if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE)
+ && (safi == Constants.VPN_SAFI_VALUE)) {
+ byte nextHopLen = tempCb.readByte();
+ InetAddress ipAddress = Validation.toInetAddress(nextHopLen, tempCb);
+ if (ipAddress.isMulticastAddress()) {
+ throw new BgpParseException("Multicast not supported");
+ }
+ ipNextHop = Ip4Address.valueOf(ipAddress);
+ byte reserved = tempCb.readByte();
+
+ while (tempCb.readableBytes() > 0) {
+ short nlriType = tempCb.readShort();
+ short totNlriLen = tempCb.readShort();
+ if (tempCb.readableBytes() < totNlriLen) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
+ }
+ tempBuf = tempCb.readBytes(totNlriLen);
+ switch (nlriType) {
+ case BgpNodeLSNlriVer4.NODE_NLRITYPE:
+ bgpLSNlri = BgpNodeLSNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BgpLinkLsNlriVer4.LINK_NLRITYPE:
+ bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BgpPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
+ bgpLSNlri = BgpPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi);
+ break;
+ default:
+ log.debug("nlriType not supported" + nlriType);
+ }
+ mpReachNlri.add(bgpLSNlri);
+ }
+ } else {
+ throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi);
+ }
+ }
+ return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength());
+ }
+
+ @Override
+ public short getType() {
+ return MPREACHNLRI_TYPE;
+ }
+
+ /**
+ * Returns AFI.
+ *
+ * @return AFI
+ */
+ public short afi() {
+ return this.afi;
+ }
+
+ /**
+ * Returns Nexthop IpAddress.
+ *
+ * @return Nexthop IpAddress
+ */
+ public Ip4Address nexthop4() {
+ return this.ipNextHop;
+ }
+
+ /**
+ * Returns SAFI.
+ *
+ * @return SAFI
+ */
+ public byte safi() {
+ return this.safi;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not to be Implemented as of now
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("mpReachNlri", mpReachNlri)
+ .add("afi", afi)
+ .add("safi", safi)
+ .add("ipNextHop", ipNextHop)
+ .add("length", length)
+ .toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
new file mode 100644
index 00000000..f354b3ea
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2015 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.LinkedList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.protocol.BgpLSNlri;
+import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of MpUnReach Nlri BGP Path Attribute.
+ */
+public class MpUnReachNlri implements BgpValueType {
+
+ private static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class);
+ public static final byte MPUNREACHNLRI_TYPE = 15;
+ public static final byte LINK_NLRITYPE = 2;
+
+ private boolean isMpUnReachNlri = false;
+ private final short afi;
+ private final byte safi;
+ private final List<BgpLSNlri> mpUnReachNlri;
+ private final int length;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param mpUnReachNlri MpUnReach Nlri attribute
+ * @param afi address family identifier
+ * @param safi subsequent address family identifier
+ * @param length of MpUnReachNlri
+ */
+ public MpUnReachNlri(List<BgpLSNlri> mpUnReachNlri, short afi, byte safi,
+ int length) {
+ this.mpUnReachNlri = mpUnReachNlri;
+ this.isMpUnReachNlri = true;
+ this.afi = afi;
+ this.safi = safi;
+ this.length = length;
+ }
+
+ /**
+ * Reads from ChannelBuffer and parses MpUnReachNlri.
+ *
+ * @param cb ChannelBuffer
+ * @return object of MpUnReachNlri
+ * @throws BgpParseException while parsing MpUnReachNlri
+ */
+ public static MpUnReachNlri read(ChannelBuffer cb) throws BgpParseException {
+ ChannelBuffer tempBuf = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT
+ : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempBuf.readBytes(len);
+
+ if (!parseFlags.getFirstBit() && parseFlags.getSecondBit()
+ && parseFlags.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ if (cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength());
+ }
+
+ LinkedList<BgpLSNlri> mpUnReachNlri = new LinkedList<>();
+ BgpLSNlri bgpLSNlri = null;
+ short afi = 0;
+ byte safi = 0;
+ ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength());
+ while (tempCb.readableBytes() > 0) {
+ afi = tempCb.readShort();
+ safi = tempCb.readByte();
+
+ //Supporting only for AFI 16388 / SAFI 71
+ if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE)
+ || (afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) {
+ while (tempCb.readableBytes() > 0) {
+ short nlriType = tempCb.readShort();
+ short totNlriLen = tempCb.readShort();
+ if (tempCb.readableBytes() < totNlriLen) {
+ Validation.validateLen(
+ BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
+ }
+ tempBuf = tempCb.readBytes(totNlriLen);
+ switch (nlriType) {
+ case BgpNodeLSNlriVer4.NODE_NLRITYPE:
+ bgpLSNlri = BgpNodeLSNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BgpLinkLsNlriVer4.LINK_NLRITYPE:
+ bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
+ break;
+ case BgpPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
+ bgpLSNlri = BgpPrefixIPv4LSNlriVer4.read(tempBuf, afi,
+ safi);
+ break;
+ default:
+ log.debug("nlriType not supported" + nlriType);
+ }
+ mpUnReachNlri.add(bgpLSNlri);
+ }
+ } else {
+ //TODO: check with the values got from capability
+ throw new BgpParseException("Not Supporting afi " + afi
+ + "safi " + safi);
+ }
+ }
+ return new MpUnReachNlri(mpUnReachNlri, afi, safi,
+ parseFlags.getLength());
+ }
+
+ @Override
+ public short getType() {
+ return MPUNREACHNLRI_TYPE;
+ }
+
+ /**
+ * Returns SAFI.
+ *
+ * @return SAFI
+ */
+ public byte safi() {
+ return this.safi;
+ }
+
+ /**
+ * Returns AFI.
+ *
+ * @return AFI
+ */
+ public short afi() {
+ return this.afi;
+ }
+
+ /**
+ * Returns list of MpUnReach Nlri.
+ *
+ * @return list of MpUnReach Nlri
+ */
+ public List<BgpLSNlri> mpUnReachNlri() {
+ return this.mpUnReachNlri;
+ }
+
+ /**
+ * Returns whether MpReachNlri is present.
+ *
+ * @return whether MpReachNlri is present
+ */
+ public boolean isMpUnReachNlriSet() {
+ return this.isMpUnReachNlri;
+ }
+
+ /**
+ * Returns length of MpUnReach.
+ *
+ * @return length of MpUnReach
+ */
+ public int mpUnReachNlriLen() {
+ return this.length;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not to be Implemented as of now
+ return 0;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("mpReachNlri", mpUnReachNlri)
+ .add("afi", afi)
+ .add("safi", safi)
+ .add("length", length)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java
new file mode 100644
index 00000000..7082483e
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MultiProtocolExtnCapabilityTlv.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides MultiProtocolExtnCapabilityTlv.
+ */
+public class MultiProtocolExtnCapabilityTlv implements BgpValueType {
+
+ /*
+ 0 7 15 23 31
+ +-------+-------+-------+-------+
+ | AFI | Res | SAFI |
+ +-------+-------+-------+-------+
+
+ Multiprotocol Extensions CAPABILITY TLV format
+ REFERENCE : RFC 4760
+ */
+ protected static final Logger log = LoggerFactory
+ .getLogger(MultiProtocolExtnCapabilityTlv.class);
+
+ public static final byte TYPE = 1;
+ public static final byte LENGTH = 4;
+
+ private final short afi;
+ private final byte res;
+ private final byte safi;
+
+ /**
+ * Constructor to initialize variables.
+ * @param afi Address Family Identifiers
+ * @param res reserved field
+ * @param safi Subsequent Address Family Identifier
+ */
+ public MultiProtocolExtnCapabilityTlv(short afi, byte res, byte safi) {
+ this.afi = afi;
+ this.res = res;
+ this.safi = safi;
+ }
+
+ /**
+ * Returns object of MultiProtocolExtnCapabilityTlv.
+ * @param afi Address Family Identifiers
+ * @param res reserved field
+ * @param safi Subsequent Address Family Identifier
+ * @return object of MultiProtocolExtnCapabilityTlv
+ */
+ public static MultiProtocolExtnCapabilityTlv of(short afi, byte res,
+ byte safi) {
+ return new MultiProtocolExtnCapabilityTlv(afi, res, safi);
+ }
+
+ /**
+ * Returns afi Address Family Identifiers value.
+ * @return afi Address Family Identifiers value
+ */
+ public short getAFI() {
+ return afi;
+ }
+
+ /**
+ * Returns res reserved field value.
+ * @return res reserved field value
+ */
+ public byte getRes() {
+ return res;
+ }
+
+ /**
+ * Returns safi Subsequent Address Family Identifier value.
+ * @return safi Subsequent Address Family Identifier value
+ */
+ public byte getSAFI() {
+ return safi;
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(afi, res, safi);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof MultiProtocolExtnCapabilityTlv) {
+ MultiProtocolExtnCapabilityTlv other = (MultiProtocolExtnCapabilityTlv) obj;
+ return Objects.equals(this.afi, other.afi)
+ && Objects.equals(this.res, other.res)
+ && Objects.equals(this.safi, other.safi);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ int iLenStartIndex = cb.writerIndex();
+ cb.writeByte(TYPE);
+ cb.writeByte(LENGTH);
+
+ // write afi
+ cb.writeShort(afi);
+
+ // write res
+ cb.writeByte(res);
+
+ // write safi
+ cb.writeByte(safi);
+
+ return cb.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads from channel buffer and returns object of MultiprotocolCapabilityTlv.
+ * @param cb of type channel buffer
+ * @return object of MultiProtocolExtnCapabilityTlv
+ */
+ public static BgpValueType read(ChannelBuffer cb) {
+ short afi = cb.readShort();
+ byte res = cb.readByte();
+ byte safi = cb.readByte();
+ return new MultiProtocolExtnCapabilityTlv(afi, res, safi);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("AFI", afi)
+ .add("Reserved", res)
+ .add("SAFI", safi).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
new file mode 100644
index 00000000..806efe52
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2015 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.net.InetAddress;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+/**
+ * Implementation of NextHop BGP Path Attribute.
+ */
+public class NextHop implements BgpValueType {
+ public static final byte NEXTHOP_TYPE = 3;
+
+ private boolean isNextHop = false;
+ private Ip4Address nextHop;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param nextHop nextHop address
+ */
+ public NextHop(Ip4Address nextHop) {
+ this.nextHop = Preconditions.checkNotNull(nextHop);
+ this.isNextHop = true;
+ }
+
+ /**
+ * Returns whether next hop is present.
+ *
+ * @return whether next hop is present
+ */
+ public boolean isNextHopSet() {
+ return this.isNextHop;
+ }
+
+ /**
+ * Reads from ChannelBuffer and parses NextHop.
+ *
+ * @param cb ChannelBuffer
+ * @return object of NextHop
+ * @throws BgpParseException while parsing nexthop attribute
+ */
+ public static NextHop read(ChannelBuffer cb) throws BgpParseException {
+ Ip4Address nextHop;
+ ChannelBuffer tempCb = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+
+ if (cb.readableBytes() < parseFlags.getLength()) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ parseFlags.getLength());
+ }
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempCb.readBytes(len);
+ if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
+ if (ipAddress.isMulticastAddress()) {
+ throw new BgpParseException("Multicast address is not supported");
+ }
+
+ nextHop = Ip4Address.valueOf(ipAddress);
+ return new NextHop(nextHop);
+ }
+
+ /**
+ * Return nexthop address.
+ *
+ * @return nexthop address
+ */
+ public Ip4Address nextHop() {
+ return nextHop;
+ }
+
+ @Override
+ public short getType() {
+ return NEXTHOP_TYPE;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not required to be implemented now
+ return 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(nextHop);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof NextHop) {
+ NextHop other = (NextHop) obj;
+ return Objects.equals(nextHop, other.nextHop);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("nextHop", nextHop)
+ .toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java
new file mode 100644
index 00000000..d281a4ef
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFNonPseudonode.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.protocol.IGPRouterID;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides implementation of OSPFNonPseudonode Tlv.
+ */
+public class OSPFNonPseudonode implements IGPRouterID, BgpValueType {
+ public static final short TYPE = 515;
+ public static final short LENGTH = 4;
+
+ private final int routerID;
+
+ /**
+ * Constructor to initialize routerID.
+ *
+ * @param routerID routerID
+ */
+ public OSPFNonPseudonode(int routerID) {
+ this.routerID = routerID;
+ }
+
+ /**
+ * Returns object of this class with specified routerID.
+ *
+ * @param routerID routerID
+ * @return object of OSPFNonPseudonode
+ */
+ public static OSPFNonPseudonode of(final int routerID) {
+ return new OSPFNonPseudonode(routerID);
+ }
+
+ /**
+ * Returns RouterID.
+ *
+ * @return RouterID
+ */
+ public int getrouterID() {
+ return this.routerID;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(routerID);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof OSPFNonPseudonode) {
+ OSPFNonPseudonode other = (OSPFNonPseudonode) obj;
+ return Objects.equals(routerID, other.routerID);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeInt(routerID);
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of OSPFNonPseudonode.
+ *
+ * @param cb ChannelBuffer
+ * @return object of OSPFNonPseudonode
+ */
+ public static OSPFNonPseudonode read(ChannelBuffer cb) {
+ return OSPFNonPseudonode.of(cb.readInt());
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Integer) (this.routerID)).compareTo((Integer) (((OSPFNonPseudonode) o).routerID));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("RouterID", routerID)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java
new file mode 100644
index 00000000..0d17651a
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFPseudonode.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.bgpio.protocol.IGPRouterID;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides implementation of OSPFPseudonode Tlv.
+ */
+public class OSPFPseudonode implements IGPRouterID, BgpValueType {
+ public static final short TYPE = 515;
+ public static final short LENGTH = 8;
+
+ private final int routerID;
+ private final Ip4Address drInterface;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param routerID routerID
+ * @param drInterface IPv4 address of the DR's interface
+ */
+ public OSPFPseudonode(int routerID, Ip4Address drInterface) {
+ this.routerID = routerID;
+ this.drInterface = drInterface;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param routerID routerID
+ * @param drInterface IPv4 address of the DR's interface
+ * @return object of OSPFPseudonode
+ */
+ public static OSPFPseudonode of(final int routerID, final Ip4Address drInterface) {
+ return new OSPFPseudonode(routerID, drInterface);
+ }
+
+ /**
+ * Returns RouterID.
+ *
+ * @return RouterID
+ */
+ public int getrouterID() {
+ return this.routerID;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(routerID, drInterface);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof OSPFPseudonode) {
+ OSPFPseudonode other = (OSPFPseudonode) obj;
+ return Objects.equals(routerID, other.routerID) && Objects.equals(drInterface, other.drInterface);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeInt(routerID);
+ c.writeInt(drInterface.toInt());
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads the channel buffer and returns object of OSPFPseudonode.
+ *
+ * @param cb ChannelBuffer
+ * @return object of OSPFPseudonode
+ */
+ public static OSPFPseudonode read(ChannelBuffer cb) {
+ int routerID = cb.readInt();
+ Ip4Address drInterface = Ip4Address.valueOf(cb.readInt());
+ return OSPFPseudonode.of(routerID, drInterface);
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int result = ((Integer) (this.routerID)).compareTo((Integer) (((OSPFPseudonode) o).routerID));
+ if (result != 0) {
+ return this.drInterface.compareTo(((OSPFPseudonode) o).drInterface);
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("RouterID", routerID)
+ .add("DRInterface", drInterface)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java
new file mode 100644
index 00000000..be321c95
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/OSPFRouteTypeTlv.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides OSPF Route Type Tlv which contains route type.
+ */
+public class OSPFRouteTypeTlv implements BgpValueType {
+
+ /* Reference :draft-ietf-idr-ls-distribution-11
+ 0 1 2 3
+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Type | Length |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Route Type |
+ +-+-+-+-+-+-+-+-+
+
+ Figure : OSPF Route Type TLV Format
+ */
+
+ public static final short TYPE = 264;
+ public static final short LENGTH = 1;
+ public static final int INTRA_AREA_TYPE = 1;
+ public static final short INTER_AREA_TYPE = 2;
+ public static final short EXTERNAL_TYPE_1 = 3;
+ public static final short EXTERNAL_TYPE_2 = 4;
+ public static final short NSSA_TYPE_1 = 5;
+ public static final short NSSA_TYPE_2 = 6;
+
+ private final byte routeType;
+
+ /**
+ * Enum for Route Type.
+ */
+ public enum RouteType {
+ Intra_Area(1), Inter_Area(2), External_1(3), External_2(4), NSSA_1(5), NSSA_2(6);
+ int value;
+ RouteType(int val) {
+ value = val;
+ }
+ public byte getType() {
+ return (byte) value;
+ }
+ }
+
+ /**
+ * Constructor to initialize routeType.
+ *
+ * @param routeType Route type
+ */
+ public OSPFRouteTypeTlv(byte routeType) {
+ this.routeType = routeType;
+ }
+
+ /**
+ * Returns object of this class with specified routeType.
+ *
+ * @param routeType Route type
+ * @return object of OSPFRouteTypeTlv
+ */
+ public static OSPFRouteTypeTlv of(final byte routeType) {
+ return new OSPFRouteTypeTlv(routeType);
+ }
+
+ /**
+ * Returns RouteType.
+ *
+ * @return RouteType
+ * @throws BgpParseException if routeType is not matched
+ */
+ public RouteType getValue() throws BgpParseException {
+ switch (routeType) {
+ case INTRA_AREA_TYPE:
+ return RouteType.Intra_Area;
+ case INTER_AREA_TYPE:
+ return RouteType.Inter_Area;
+ case EXTERNAL_TYPE_1:
+ return RouteType.External_1;
+ case EXTERNAL_TYPE_2:
+ return RouteType.External_2;
+ case NSSA_TYPE_1:
+ return RouteType.NSSA_1;
+ case NSSA_TYPE_2:
+ return RouteType.NSSA_2;
+ default:
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(routeType);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof OSPFRouteTypeTlv) {
+ OSPFRouteTypeTlv other = (OSPFRouteTypeTlv) obj;
+ return Objects.equals(routeType, other.routeType);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer c) {
+ int iLenStartIndex = c.writerIndex();
+ c.writeShort(TYPE);
+ c.writeShort(LENGTH);
+ c.writeByte(routeType);
+ return c.writerIndex() - iLenStartIndex;
+ }
+
+ /**
+ * Reads from ChannelBuffer and parses OSPFRouteTypeTlv.
+ *
+ * @param cb channelBuffer
+ * @return object of OSPFRouteTypeTlv
+ */
+ public static OSPFRouteTypeTlv read(ChannelBuffer cb) {
+ return OSPFRouteTypeTlv.of(cb.readByte());
+ }
+
+ @Override
+ public short getType() {
+ return TYPE;
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ return ((Byte) (this.routeType)).compareTo((Byte) (((OSPFRouteTypeTlv) o).routeType));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("Type", TYPE)
+ .add("Length", LENGTH)
+ .add("Value", routeType)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
new file mode 100644
index 00000000..d642d83c
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.util.Constants;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Provides Implementation of mandatory BGP Origin path attribute.
+ */
+public class Origin implements BgpValueType {
+
+ /**
+ * Enum to provide ORIGIN types.
+ */
+ public enum ORIGINTYPE {
+ IGP(0), EGP(1), INCOMPLETE(2);
+ int value;
+ /**
+ * Assign val with the value as the ORIGIN type.
+ *
+ * @param val ORIGIN type
+ */
+ ORIGINTYPE(int val) {
+ value = val;
+ }
+
+ /**
+ * Returns value of ORIGIN type.
+ *
+ * @return ORIGIN type
+ */
+ public byte getType() {
+ return (byte) value;
+ }
+ }
+
+ public static final byte ORIGIN_TYPE = 1;
+ public static final byte ORIGIN_VALUE_LEN = 1;
+
+ private boolean isOrigin = false;
+ private byte origin;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param origin origin value
+ */
+ public Origin(byte origin) {
+ this.origin = origin;
+ this.isOrigin = true;
+ }
+
+ /**
+ * Returns true if origin attribute is present otherwise false.
+ *
+ * @return whether origin is present or not
+ */
+ public boolean isOriginSet() {
+ return this.isOrigin;
+ }
+
+ /**
+ * Returns type of Origin in Enum values.
+ *
+ * @return type of Origin in Enum values
+ */
+ public ORIGINTYPE origin() {
+ if (this.origin == 0) {
+ return ORIGINTYPE.IGP;
+ } else if (this.origin == 1) {
+ return ORIGINTYPE.EGP;
+ } else {
+ return ORIGINTYPE.INCOMPLETE;
+ }
+ }
+
+ /**
+ * Reads from ChannelBuffer and parses Origin.
+ *
+ * @param cb ChannelBuffer
+ * @return object of Origin
+ * @throws BgpParseException while parsing Origin path attribute
+ */
+ public static Origin read(ChannelBuffer cb) throws BgpParseException {
+ ChannelBuffer tempCb = cb.copy();
+ Validation parseFlags = Validation.parseAttributeHeader(cb);
+
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
+ ChannelBuffer data = tempCb.readBytes(len);
+ if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ parseFlags.getLength());
+ }
+ if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
+ }
+
+ byte originValue;
+ originValue = cb.readByte();
+ if ((originValue != ORIGINTYPE.INCOMPLETE.value) && (originValue != ORIGINTYPE.IGP.value) &&
+ (originValue != ORIGINTYPE.EGP.value)) {
+ throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
+ }
+ return new Origin(originValue);
+ }
+
+ @Override
+ public short getType() {
+ return ORIGIN_TYPE;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ //Not required to Implement as of now
+ return 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(origin);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof Origin) {
+ Origin other = (Origin) obj;
+ return Objects.equals(origin, other.origin);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("origin", origin)
+ .toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java
new file mode 100644
index 00000000..37632ad8
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/RouteDistinguisher.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2015 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 org.jboss.netty.buffer.ChannelBuffer;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implementation of RouteDistinguisher.
+ */
+public class RouteDistinguisher implements Comparable<RouteDistinguisher> {
+
+ private long routeDistinguisher;
+
+ /**
+ * Resets fields.
+ */
+ public RouteDistinguisher() {
+ this.routeDistinguisher = 0;
+ }
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param routeDistinguisher route distinguisher
+ */
+ public RouteDistinguisher(long routeDistinguisher) {
+ this.routeDistinguisher = routeDistinguisher;
+ }
+
+ /**
+ * Reads route distinguisher from channelBuffer.
+ *
+ * @param cb channelBuffer
+ * @return object of RouteDistinguisher
+ */
+ public static RouteDistinguisher read(ChannelBuffer cb) {
+ return new RouteDistinguisher(cb.readLong());
+ }
+
+ /**
+ * Returns route distinguisher.
+ *
+ * @return route distinguisher
+ */
+ public long getRouteDistinguisher() {
+ return this.routeDistinguisher;
+ }
+
+ @Override
+ public int compareTo(RouteDistinguisher rd) {
+ if (this.equals(rd)) {
+ return 0;
+ }
+ return ((Long) (this.getRouteDistinguisher())).compareTo((Long) (rd.getRouteDistinguisher()));
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("routeDistinguisher", routeDistinguisher)
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java
new file mode 100755
index 00000000..e0fef7c8
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlv.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute node flag.
+ */
+public final class BgpAttrNodeFlagBitTlv implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrNodeFlagBitTlv.class);
+
+ public static final int ATTRNODE_FLAGBIT = 1024;
+
+ /* Node flag bit TLV */
+ private final boolean bOverloadBit;
+ private final boolean bAttachedBit;
+ private final boolean bExternalBit;
+ private final boolean bAbrBit;
+
+ public static final byte FIRST_BIT = (byte) 0x80;
+ public static final byte SECOND_BIT = 0x40;
+ public static final byte THIRD_BIT = 0x20;
+ public static final byte FOURTH_BIT = 0x01;
+
+ /**
+ * Constructor to initialize parameters.
+ *
+ * @param bOverloadBit Overload bit
+ * @param bAttachedBit Attached bit
+ * @param bExternalBit External bit
+ * @param bAbrBit ABR Bit
+ */
+ private BgpAttrNodeFlagBitTlv(boolean bOverloadBit, boolean bAttachedBit,
+ boolean bExternalBit, boolean bAbrBit) {
+ this.bOverloadBit = bOverloadBit;
+ this.bAttachedBit = bAttachedBit;
+ this.bExternalBit = bExternalBit;
+ this.bAbrBit = bAbrBit;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param bOverloadBit Overload bit
+ * @param bAttachedBit Attached bit
+ * @param bExternalBit External bit
+ * @param bAbrBit ABR Bit
+ * @return object of BgpAttrNodeFlagBitTlv
+ */
+ public static BgpAttrNodeFlagBitTlv of(final boolean bOverloadBit,
+ final boolean bAttachedBit,
+ final boolean bExternalBit,
+ final boolean bAbrBit) {
+ return new BgpAttrNodeFlagBitTlv(bOverloadBit, bAttachedBit,
+ bExternalBit, bAbrBit);
+ }
+
+ /**
+ * Reads the Node Flag Bits.
+ *
+ * @param cb ChannelBuffer
+ * @return attribute node flag bit tlv
+ * @throws BgpParseException while parsing BgpAttrNodeFlagBitTlv
+ */
+ public static BgpAttrNodeFlagBitTlv read(ChannelBuffer cb)
+ throws BgpParseException {
+ boolean bOverloadBit = false;
+ boolean bAttachedBit = false;
+ boolean bExternalBit = false;
+ boolean bAbrBit = false;
+
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != 1) || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ byte nodeFlagBits = cb.readByte();
+
+ bOverloadBit = ((nodeFlagBits & FIRST_BIT) == FIRST_BIT);
+ bAttachedBit = ((nodeFlagBits & SECOND_BIT) == SECOND_BIT);
+ bExternalBit = ((nodeFlagBits & THIRD_BIT) == THIRD_BIT);
+ bAbrBit = ((nodeFlagBits & FOURTH_BIT) == FOURTH_BIT);
+
+ return BgpAttrNodeFlagBitTlv.of(bOverloadBit, bAttachedBit,
+ bExternalBit, bAbrBit);
+ }
+
+ /**
+ * Returns Overload Bit.
+ *
+ * @return Overload Bit
+ */
+ public boolean overLoadBit() {
+ return bOverloadBit;
+ }
+
+ /**
+ * Returns Attached Bit.
+ *
+ * @return Attached Bit
+ */
+ public boolean attachedBit() {
+ return bAttachedBit;
+ }
+
+ /**
+ * Returns External Bit.
+ *
+ * @return External Bit
+ */
+ public boolean externalBit() {
+ return bExternalBit;
+ }
+
+ /**
+ * Returns ABR Bit.
+ *
+ * @return ABR Bit
+ */
+ public boolean abrBit() {
+ return bAbrBit;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_FLAGBIT;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(bOverloadBit, bAttachedBit, bExternalBit, bAbrBit);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrNodeFlagBitTlv) {
+ BgpAttrNodeFlagBitTlv other = (BgpAttrNodeFlagBitTlv) obj;
+ return Objects.equals(bOverloadBit, other.bOverloadBit)
+ && Objects.equals(bAttachedBit, other.bAttachedBit)
+ && Objects.equals(bExternalBit, other.bExternalBit)
+ && Objects.equals(bAbrBit, other.bAbrBit);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("bOverloadBit", bOverloadBit)
+ .add("bAttachedBit", bAttachedBit)
+ .add("bExternalBit", bExternalBit).add("bAbrBit", bAbrBit)
+ .toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java
new file mode 100644
index 00000000..0435a65f
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeIsIsAreaId.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute ISIS Area Identifier.
+ */
+public class BgpAttrNodeIsIsAreaId implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrNodeIsIsAreaId.class);
+
+ public static final int ATTRNODE_ISISAREAID = 1027;
+
+ /* IS-IS Area Identifier TLV */
+ private byte[] isisAreaId;
+
+ /**
+ * Constructor to initialize value.
+ *
+ * @param isisAreaId ISIS area Identifier
+ */
+ public BgpAttrNodeIsIsAreaId(byte[] isisAreaId) {
+ this.isisAreaId = Arrays.copyOf(isisAreaId, isisAreaId.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param isisAreaId ISIS area Identifier
+ * @return object of BgpAttrNodeIsIsAreaId
+ */
+ public static BgpAttrNodeIsIsAreaId of(final byte[] isisAreaId) {
+ return new BgpAttrNodeIsIsAreaId(isisAreaId);
+ }
+
+ /**
+ * Reads the IS-IS Area Identifier.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpAttrNodeIsIsAreaId
+ * @throws BgpParseException while parsing BgpAttrNodeIsIsAreaId
+ */
+ public static BgpAttrNodeIsIsAreaId read(ChannelBuffer cb)
+ throws BgpParseException {
+ byte[] isisAreaId;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ isisAreaId = new byte[lsAttrLength];
+ cb.readBytes(isisAreaId);
+
+ return BgpAttrNodeIsIsAreaId.of(isisAreaId);
+ }
+
+ /**
+ * Returns ISIS area Identifier.
+ *
+ * @return Area ID
+ */
+ public byte[] attrNodeIsIsAreaId() {
+ return isisAreaId;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_ISISAREAID;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(isisAreaId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrNodeIsIsAreaId) {
+ BgpAttrNodeIsIsAreaId other = (BgpAttrNodeIsIsAreaId) obj;
+ return Arrays.equals(isisAreaId, other.isisAreaId);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("isisAreaId", isisAreaId).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
new file mode 100644
index 00000000..31d855db
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * BGP Multi-Topology ID of the LS attribute.
+ */
+public class BgpAttrNodeMultiTopologyId implements BgpValueType {
+
+ private static final Logger log = LoggerFactory
+ .getLogger(BgpAttrNodeMultiTopologyId.class);
+
+ public static final int ATTRNODE_MULTITOPOLOGY = 263;
+
+ /* Opaque Node Attribute */
+ private List<Short> multiTopologyId = new ArrayList<Short>();
+
+ /**
+ * Constructor to initialize the Node attribute multi-topology ID.
+ *
+ * @param multiTopologyId multi-topology ID
+ */
+ public BgpAttrNodeMultiTopologyId(List<Short> multiTopologyId) {
+ this.multiTopologyId = multiTopologyId;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param multiTopologyId Prefix Metric
+ * @return object of BgpAttrNodeMultiTopologyId
+ */
+ public static BgpAttrNodeMultiTopologyId of(ArrayList<Short> multiTopologyId) {
+ return new BgpAttrNodeMultiTopologyId(multiTopologyId);
+ }
+
+ /**
+ * Reads the Multi-topology ID of Node attribute.
+ *
+ * @param cb ChannelBuffer
+ * @return Constructor of BgpAttrNodeMultiTopologyId
+ * @throws BgpParseException while parsing BgpAttrNodeMultiTopologyId
+ */
+ public static BgpAttrNodeMultiTopologyId read(ChannelBuffer cb)
+ throws BgpParseException {
+ ArrayList<Short> multiTopologyId = new ArrayList<Short>();
+ short tempMultiTopologyId;
+ short lsAttrLength = cb.readShort();
+ int len = lsAttrLength / 2; // Length is 2*n and n is the number of MT-IDs
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < len; i++) {
+ tempMultiTopologyId = cb.readShort();
+ multiTopologyId.add(new Short(tempMultiTopologyId));
+ }
+
+ return new BgpAttrNodeMultiTopologyId(multiTopologyId);
+ }
+
+ /**
+ * to get the multi-topology ID.
+ *
+ * @return multitopology ID
+ */
+ public List<Short> attrMultiTopologyId() {
+ return multiTopologyId;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_MULTITOPOLOGY;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(multiTopologyId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrNodeMultiTopologyId) {
+ BgpAttrNodeMultiTopologyId other = (BgpAttrNodeMultiTopologyId) obj;
+ return Objects.equals(multiTopologyId, other.multiTopologyId);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("multiTopologyId", multiTopologyId)
+ .toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.equals(o)) {
+ return 0;
+ }
+ int countOtherSubTlv = ((BgpAttrNodeMultiTopologyId) o).multiTopologyId.size();
+ int countObjSubTlv = multiTopologyId.size();
+ if (countOtherSubTlv != countObjSubTlv) {
+ if (countOtherSubTlv > countObjSubTlv) {
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+ ListIterator<Short> listIterator = multiTopologyId.listIterator();
+ ListIterator<Short> listIteratorOther = ((BgpAttrNodeMultiTopologyId) o).multiTopologyId.listIterator();
+ while (listIterator.hasNext()) {
+ short id = listIterator.next();
+ short id1 = listIteratorOther.next();
+ if (((Short) id).compareTo((Short) id1) != 0) {
+ return ((Short) id).compareTo((Short) id1);
+ }
+ }
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java
new file mode 100644
index 00000000..2e1c7a05
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeName.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute node name.
+ */
+public class BgpAttrNodeName implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrNodeName.class);
+
+ public static final int ATTRNODE_NAME = 1026;
+
+ /* Node Name */
+ private byte[] nodeName;
+
+ /**
+ * Constructor to initialize value.
+ *
+ * @param nodeName node name
+ */
+ public BgpAttrNodeName(byte[] nodeName) {
+ this.nodeName = Arrays.copyOf(nodeName, nodeName.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param nodeName node name
+ * @return object of BgpAttrNodeName
+ */
+ public static BgpAttrNodeName of(final byte[] nodeName) {
+ return new BgpAttrNodeName(nodeName);
+ }
+
+ /**
+ * Reads the LS attribute node name.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpAttrNodeName
+ * @throws BgpParseException while parsing BgpAttrNodeName
+ */
+ public static BgpAttrNodeName read(ChannelBuffer cb)
+ throws BgpParseException {
+ byte[] nodeName;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ nodeName = new byte[lsAttrLength];
+ cb.readBytes(nodeName);
+ return BgpAttrNodeName.of(nodeName);
+ }
+
+ /**
+ * Returns LS attribute node name.
+ *
+ * @return node name
+ */
+ public byte[] attrNodeName() {
+ return nodeName;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_NAME;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(nodeName);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrNodeName) {
+ BgpAttrNodeName other = (BgpAttrNodeName) obj;
+ return Arrays.equals(nodeName, other.nodeName);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("nodeName", nodeName).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java
new file mode 100644
index 00000000..545755a7
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrOpaqueNode.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute opaque node.
+ */
+public class BgpAttrOpaqueNode implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrOpaqueNode.class);
+
+ public static final int ATTRNODE_OPAQUEDATA = 1025;
+
+ /* Opaque Node Attribute */
+ private byte[] opaqueNodeAttribute;
+
+ /**
+ * Constructor to initialize parameter.
+ *
+ * @param opaqueNodeAttribute opaque node attribute
+ */
+ public BgpAttrOpaqueNode(byte[] opaqueNodeAttribute) {
+ this.opaqueNodeAttribute = Arrays.copyOf(opaqueNodeAttribute, opaqueNodeAttribute.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param opaqueNodeAttribute Prefix Metric
+ * @return object of BgpAttrOpaqueNode
+ */
+ public static BgpAttrOpaqueNode of(byte[] opaqueNodeAttribute) {
+ return new BgpAttrOpaqueNode(opaqueNodeAttribute);
+ }
+
+ /**
+ * Reads the Opaque Node Properties.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpAttrOpaqueNode
+ * @throws BgpParseException while parsing BgpAttrOpaqueNode
+ */
+ public static BgpAttrOpaqueNode read(ChannelBuffer cb)
+ throws BgpParseException {
+
+ byte[] opaqueNodeAttribute;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ opaqueNodeAttribute = new byte[lsAttrLength];
+ cb.readBytes(opaqueNodeAttribute);
+
+ return BgpAttrOpaqueNode.of(opaqueNodeAttribute);
+ }
+
+ /**
+ * Returns opaque node attribute.
+ *
+ * @return LS node attribute value
+ */
+ public byte[] attrOpaqueNode() {
+ return opaqueNodeAttribute;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_OPAQUEDATA;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(opaqueNodeAttribute);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrOpaqueNode) {
+ BgpAttrOpaqueNode other = (BgpAttrOpaqueNode) obj;
+ return Arrays
+ .equals(opaqueNodeAttribute, other.opaqueNodeAttribute);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("opaqueNodeAttribute", opaqueNodeAttribute).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java
new file mode 100644
index 00000000..f3c0d17b
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV4.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute node router ID.
+ */
+public final class BgpAttrRouterIdV4 implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrRouterIdV4.class);
+
+ private final short sType;
+
+ /* IPv4 Router-ID of Node */
+ private final Ip4Address ip4RouterId;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param ip4RouterId IPV4 address of router
+ * @param sType TLV type
+ */
+ private BgpAttrRouterIdV4(Ip4Address ip4RouterId, short sType) {
+ this.ip4RouterId = ip4RouterId;
+ this.sType = sType;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param ip4RouterId IPv4 address
+ * @param sType Type of this TLV
+ * @return object of BgpAttrRouterIdV4
+ */
+ public static BgpAttrRouterIdV4 of(final Ip4Address ip4RouterId,
+ final short sType) {
+ return new BgpAttrRouterIdV4(ip4RouterId, sType);
+ }
+
+ /**
+ * Reads the IPv4 Router-ID.
+ *
+ * @param cb ChannelBuffer
+ * @param sType tag type
+ * @return object of BgpAttrRouterIdV4
+ * @throws BgpParseException while parsing BgpAttrRouterIdV4
+ */
+ public static BgpAttrRouterIdV4 read(ChannelBuffer cb, short sType)
+ throws BgpParseException {
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != 4) || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ byte[] ipBytes = new byte[lsAttrLength];
+ cb.readBytes(ipBytes, 0, lsAttrLength);
+ Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
+ return BgpAttrRouterIdV4.of(ip4RouterId, sType);
+ }
+
+ /**
+ * Returns the IPV4 router ID.
+ *
+ * @return Router ID
+ */
+ public Ip4Address attrRouterId() {
+ return ip4RouterId;
+ }
+
+ @Override
+ public short getType() {
+ return sType;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ip4RouterId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrRouterIdV4) {
+ BgpAttrRouterIdV4 other = (BgpAttrRouterIdV4) obj;
+ return Objects.equals(ip4RouterId, other.ip4RouterId);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("ip4RouterId", ip4RouterId).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
new file mode 100644
index 00000000..648fd56e
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip6Address;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute IPv6 router ID.
+ */
+public final class BgpAttrRouterIdV6 implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpAttrRouterIdV6.class);
+
+ private final short sType;
+
+ /* IPv4 Router-ID of Node */
+ private final Ip6Address ip6RouterId;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param ip6RouterId IPV6 address of the router ID
+ * @param sType TLV type
+ */
+ private BgpAttrRouterIdV6(Ip6Address ip6RouterId, short sType) {
+ this.ip6RouterId = ip6RouterId;
+ this.sType = sType;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param ip6RouterId IPV6 address of the router ID
+ * @param sType TLV type
+ * @return object of BgpAttrRouterIdV6
+ */
+ public static BgpAttrRouterIdV6 of(final Ip6Address ip6RouterId,
+ final short sType) {
+ return new BgpAttrRouterIdV6(ip6RouterId, sType);
+ }
+
+ /**
+ * Reads the IPv6 Router-ID.
+ *
+ * @param cb ChannelBuffer
+ * @param sType TLV type
+ * @return object of BgpAttrRouterIdV6
+ * @throws BgpParseException while parsing BgpAttrRouterIdV6
+ */
+ public static BgpAttrRouterIdV6 read(ChannelBuffer cb, short sType)
+ throws BgpParseException {
+ byte[] ipBytes;
+ Ip6Address ip6RouterId;
+
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != 16) || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ ipBytes = new byte[lsAttrLength];
+ cb.readBytes(ipBytes);
+ ip6RouterId = Ip6Address.valueOf(ipBytes);
+ return BgpAttrRouterIdV6.of(ip6RouterId, sType);
+ }
+
+ /**
+ * Returns IPV6 router ID.
+ *
+ * @return Router ID
+ */
+ public Ip6Address attrRouterId() {
+ return ip6RouterId;
+ }
+
+ @Override
+ public short getType() {
+ return sType;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ip6RouterId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpAttrRouterIdV6) {
+ BgpAttrRouterIdV6 other = (BgpAttrRouterIdV6) obj;
+ return Objects.equals(ip6RouterId, other.ip6RouterId);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("ip6RouterId", ip6RouterId).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java
new file mode 100644
index 00000000..5721cf6c
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetric.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP link IGP metric attribute.
+ */
+public class BgpLinkAttrIgpMetric implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrIgpMetric.class);
+
+ public static final int ATTRLINK_IGPMETRIC = 1095;
+ public static final int ATTRLINK_MAX_LEN = 3;
+
+ /* Variable metric length based on protocol */
+ public static final int ISIS_SMALL_METRIC = 1;
+ public static final int OSPF_LINK_METRIC = 2;
+ public static final int ISIS_WIDE_METRIC = 3;
+
+ /* IGP Metric */
+ private final int igpMetric;
+ private final int igpMetricLen;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param igpMetric 3 byte IGP metric data.
+ * @param igpMetricLen length of IGP metric data.
+ */
+ public BgpLinkAttrIgpMetric(final int igpMetric, final int igpMetricLen) {
+ this.igpMetric = igpMetric;
+ this.igpMetricLen = igpMetricLen;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param igpMetric 3 byte IGP metric data.
+ * @param igpMetricLen length of IGP metric data.
+ * @return object of BgpLinkAttrIgpMetric
+ */
+ public static BgpLinkAttrIgpMetric of(final int igpMetric,
+ final int igpMetricLen) {
+ return new BgpLinkAttrIgpMetric(igpMetric, igpMetricLen);
+ }
+
+ /**
+ * Reads the BGP link attributes IGP Metric.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrIgpMetric
+ * @throws BgpParseException while parsing BgpLinkAttrIgpMetric
+ */
+ public static BgpLinkAttrIgpMetric read(ChannelBuffer cb)
+ throws BgpParseException {
+
+ short linkigp;
+ int igpMetric = 0;
+ int igpMetricLen = 0;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength
+ || lsAttrLength > ATTRLINK_MAX_LEN) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ switch (lsAttrLength) {
+ case ISIS_SMALL_METRIC:
+ igpMetric = cb.readByte();
+ igpMetricLen = ISIS_SMALL_METRIC;
+ break;
+ case OSPF_LINK_METRIC:
+ igpMetric = cb.readShort();
+ igpMetricLen = OSPF_LINK_METRIC;
+ break;
+ case ISIS_WIDE_METRIC:
+ linkigp = cb.readShort();
+ igpMetric = cb.readByte();
+ igpMetric = (igpMetric << 16) | linkigp;
+ igpMetricLen = ISIS_WIDE_METRIC;
+ break;
+ default: // validation is already in place
+ break;
+ }
+
+ return BgpLinkAttrIgpMetric.of(igpMetric, igpMetricLen);
+ }
+
+ /**
+ * Returns the variable length IGP metric data.
+ *
+ * @return IGP metric data
+ */
+ public int attrLinkIgpMetric() {
+ return igpMetric;
+ }
+
+ /**
+ * Returns IGP metric data length.
+ *
+ * @return IGP metric length
+ */
+ public int attrLinkIgpMetricLength() {
+ return igpMetricLen;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRLINK_IGPMETRIC;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(igpMetric, igpMetricLen);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrIgpMetric) {
+ BgpLinkAttrIgpMetric other = (BgpLinkAttrIgpMetric) obj;
+ return Objects.equals(igpMetric, other.igpMetric)
+ && Objects.equals(igpMetricLen, other.igpMetricLen);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("igpMetric", igpMetric).add("igpMetricLen", igpMetricLen)
+ .toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java
new file mode 100644
index 00000000..448f1e58
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute Is Is Administrative area.
+ */
+public final class BgpLinkAttrIsIsAdminstGrp implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrIsIsAdminstGrp.class);
+
+ public static final int ATTRLINK_PROTECTIONTYPE = 1088;
+ public static final int ISIS_ADMIN_DATA_LEN = 4;
+
+ /* ISIS administrative group */
+ private final long isisAdminGrp;
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param isisAdminGrp ISIS protocol admin group
+ */
+ public BgpLinkAttrIsIsAdminstGrp(long isisAdminGrp) {
+ this.isisAdminGrp = isisAdminGrp;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param isisAdminGrp ISIS admin group
+ * @return object of BgpLinkAttrIsIsAdminstGrp
+ */
+ public static BgpLinkAttrIsIsAdminstGrp of(final long isisAdminGrp) {
+ return new BgpLinkAttrIsIsAdminstGrp(isisAdminGrp);
+ }
+
+ /**
+ * Reads the BGP link attributes of ISIS administrative group area.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrIsIsAdminstGrp
+ * @throws BgpParseException while parsing BgpLinkAttrIsIsAdminstGrp
+ */
+ public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb)
+ throws BgpParseException {
+ long isisAdminGrp;
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != ISIS_ADMIN_DATA_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ isisAdminGrp = cb.readUnsignedInt();
+
+ return BgpLinkAttrIsIsAdminstGrp.of(isisAdminGrp);
+ }
+
+ /**
+ * Link attributes of ISIS administrative group area.
+ *
+ * @return long value of the administrative group area
+ */
+ public long linkAttrIsIsAdminGrp() {
+ return isisAdminGrp;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRLINK_PROTECTIONTYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(isisAdminGrp);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrIsIsAdminstGrp) {
+ BgpLinkAttrIsIsAdminstGrp other = (BgpLinkAttrIsIsAdminstGrp) obj;
+ return Objects.equals(isisAdminGrp, other.isisAdminGrp);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("isisAdminGrp", isisAdminGrp).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java
new file mode 100644
index 00000000..2711ca94
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP attribute Max Link bandwidth.
+ */
+public final class BgpLinkAttrMaxLinkBandwidth implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrMaxLinkBandwidth.class);
+
+ public static final int MAX_BANDWIDTH_LEN = 4;
+ public static final int NO_OF_BITS = 8;
+
+ public short type;
+
+ /* ISIS administrative group */
+ private final float maxBandwidth;
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param maxBandwidth Maximum link bandwidth.
+ * @param type TLV type
+ */
+ private BgpLinkAttrMaxLinkBandwidth(float maxBandwidth, short type) {
+ this.maxBandwidth = maxBandwidth;
+ this.type = type;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param maxBandwidth Maximum link bandwidth.
+ * @param type TLV type
+ * @return object of BgpLinkAttrMaxLinkBandwidth
+ */
+ public static BgpLinkAttrMaxLinkBandwidth of(final float maxBandwidth,
+ final short type) {
+ return new BgpLinkAttrMaxLinkBandwidth(maxBandwidth, type);
+ }
+
+ /**
+ * Reads the BGP link attributes of Maximum link bandwidth.
+ *
+ * @param cb Channel buffer
+ * @param type type of this tlv
+ * @return object of type BgpLinkAttrMaxLinkBandwidth
+ * @throws BgpParseException while parsing BgpLinkAttrMaxLinkBandwidth
+ */
+ public static BgpLinkAttrMaxLinkBandwidth read(ChannelBuffer cb, short type)
+ throws BgpParseException {
+ float maxBandwidth;
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != MAX_BANDWIDTH_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ maxBandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS;
+
+ return BgpLinkAttrMaxLinkBandwidth.of(maxBandwidth, type);
+ }
+
+ /**
+ * Returns Maximum link bandwidth.
+ *
+ * @return Maximum link bandwidth
+ */
+ float linkAttrMaxLinkBandwidth() {
+ return maxBandwidth;
+ }
+
+ /**
+ * Parse the IEEE floating point notation and returns it in normal float.
+ *
+ * @param iVal IEEE floating point number
+ * @return normal float
+ */
+ static float ieeeToFloatRead(int iVal) {
+ iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
+ | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
+
+ return Float.intBitsToFloat(iVal);
+ }
+
+ @Override
+ public short getType() {
+ return this.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(maxBandwidth);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrMaxLinkBandwidth) {
+ BgpLinkAttrMaxLinkBandwidth other = (BgpLinkAttrMaxLinkBandwidth) obj;
+ return Objects.equals(maxBandwidth, other.maxBandwidth);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("maxBandwidth", maxBandwidth).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java
new file mode 100644
index 00000000..2bf1a59d
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMask.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP MPLS protocol mask attribute.
+ */
+public class BgpLinkAttrMplsProtocolMask implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrMplsProtocolMask.class);
+
+ public static final int ATTRLINK_MPLSPROTOMASK = 1094;
+ public static final int MASK_BYTE_LEN = 1;
+
+ private final boolean bLdp;
+ private final boolean bRsvpTe;
+
+ public static final byte FIRST_BIT = (byte) 0x80;
+ public static final byte SECOND_BIT = 0x40;
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param bLdp boolean value true if LDP flag is available
+ * @param bRsvpTe boolean value true if RSVP TE information is available
+ */
+ public BgpLinkAttrMplsProtocolMask(boolean bLdp, boolean bRsvpTe) {
+ this.bLdp = bLdp;
+ this.bRsvpTe = bRsvpTe;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param bLdp boolean value true if LDP flag is available
+ * @param bRsvpTe boolean value true if RSVP TE information is available
+ * @return object of BgpLinkAttrMplsProtocolMask
+ */
+ public static BgpLinkAttrMplsProtocolMask of(final boolean bLdp,
+ final boolean bRsvpTe) {
+ return new BgpLinkAttrMplsProtocolMask(bLdp, bRsvpTe);
+ }
+
+ /**
+ * Reads the BGP link attributes MPLS protocol mask.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrMPLSProtocolMask
+ * @throws BgpParseException while parsing BgpLinkAttrMplsProtocolMask
+ */
+ public static BgpLinkAttrMplsProtocolMask read(ChannelBuffer cb)
+ throws BgpParseException {
+ boolean bLdp = false;
+ boolean bRsvpTe = false;
+
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != MASK_BYTE_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ byte flags = cb.readByte();
+
+ bLdp = ((flags & (byte) FIRST_BIT) == FIRST_BIT);
+ bRsvpTe = ((flags & (byte) SECOND_BIT) == SECOND_BIT);
+
+ return BgpLinkAttrMplsProtocolMask.of(bLdp, bRsvpTe);
+ }
+
+ /**
+ * Returns true if LDP bit is set.
+ *
+ * @return True if LDP information is set else false.
+ */
+ public boolean ldpBit() {
+ return bLdp;
+ }
+
+ /**
+ * Returns RSVP TE information.
+ *
+ * @return True if RSVP TE information is set else false.
+ */
+ public boolean rsvpBit() {
+ return bRsvpTe;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRLINK_MPLSPROTOMASK;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(bLdp, bRsvpTe);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrMplsProtocolMask) {
+ BgpLinkAttrMplsProtocolMask other = (BgpLinkAttrMplsProtocolMask) obj;
+ return Objects.equals(bLdp, other.bLdp)
+ && Objects.equals(bRsvpTe, other.bRsvpTe);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("bLdp", bLdp).add("bRsvpTe", bRsvpTe).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
new file mode 100644
index 00000000..856ffc36
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP link name attribute.
+ */
+public class BgpLinkAttrName implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrName.class);
+
+ public static final int ATTRLINK_NAME = 1098;
+
+ /* Link Name */
+ private byte[] linkName;
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param linkName link name
+ */
+ public BgpLinkAttrName(byte[] linkName) {
+ this.linkName = Arrays.copyOf(linkName, linkName.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param linkName Prefix Metric
+ * @return object of BgpLinkAttrName
+ */
+ public static BgpLinkAttrName of(byte[] linkName) {
+ return new BgpLinkAttrName(linkName);
+ }
+
+ /**
+ * Reads the BGP link attributes Name.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrName
+ * @throws BgpParseException while parsing BgpLinkAttrName
+ */
+ public static BgpLinkAttrName read(ChannelBuffer cb)
+ throws BgpParseException {
+ byte[] linkName;
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ linkName = new byte[lsAttrLength];
+ cb.readBytes(linkName);
+ return BgpLinkAttrName.of(linkName);
+ }
+
+ /**
+ * Returns the link name.
+ *
+ * @return link name
+ */
+ public byte[] attrLinkName() {
+ return linkName;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRLINK_NAME;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(linkName);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrName) {
+ BgpLinkAttrName other = (BgpLinkAttrName) obj;
+ return Arrays.equals(linkName, other.linkName);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("linkName", linkName).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java
new file mode 100644
index 00000000..275b85be
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP link opaque attribute.
+ */
+public final class BgpLinkAttrOpaqLnkAttrib implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrOpaqLnkAttrib.class);
+
+ public static final int ATTRNODE_OPAQUELNKATTRIB = 1097;
+
+ /* Opaque Node Attribute */
+ private final byte[] opaqueLinkAttribute;
+
+ /**
+ * Constructor to initialize the data.
+ *
+ * @param opaqueLinkAttribute opaque link attribute
+ */
+ private BgpLinkAttrOpaqLnkAttrib(byte[] opaqueLinkAttribute) {
+ this.opaqueLinkAttribute = Arrays.copyOf(opaqueLinkAttribute,
+ opaqueLinkAttribute.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param opaqueLinkAttribute opaque link attribute
+ * @return object of BgpLinkAttrOpaqLnkAttrib
+ */
+ public static BgpLinkAttrOpaqLnkAttrib of(final byte[] opaqueLinkAttribute) {
+ return new BgpLinkAttrOpaqLnkAttrib(opaqueLinkAttribute);
+ }
+
+ /**
+ * Reads the BGP link attributes Opaque link attribute.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrOpaqLnkAttrib
+ * @throws BgpParseException while parsing BgpLinkAttrOpaqLnkAttrib
+ */
+ public static BgpLinkAttrOpaqLnkAttrib read(ChannelBuffer cb)
+ throws BgpParseException {
+
+ byte[] opaqueLinkAttribute;
+
+ short lsAttrLength = cb.readShort();
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ opaqueLinkAttribute = new byte[lsAttrLength];
+ cb.readBytes(opaqueLinkAttribute);
+
+ return BgpLinkAttrOpaqLnkAttrib.of(opaqueLinkAttribute);
+ }
+
+ /**
+ * Returns the Opaque link attribute.
+ *
+ * @return byte array of opaque link attribute.
+ */
+ public byte[] attrOpaqueLnk() {
+ return opaqueLinkAttribute;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_OPAQUELNKATTRIB;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(opaqueLinkAttribute);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrOpaqLnkAttrib) {
+ BgpLinkAttrOpaqLnkAttrib other = (BgpLinkAttrOpaqLnkAttrib) obj;
+ return Arrays
+ .equals(opaqueLinkAttribute, other.opaqueLinkAttribute);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("opaqueLinkAttribute", opaqueLinkAttribute).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java
new file mode 100644
index 00000000..59011d97
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionType.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP link protection type attribute.
+ */
+public final class BgpLinkAttrProtectionType implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrProtectionType.class);
+
+ public static final int ATTRLINK_PROTECTIONTYPE = 1093;
+ public static final int LINK_PROTECTION_LEN = 2;
+
+ public static final int EXTRA_TRAFFIC = 0x01;
+ public static final int UNPROTECTED = 0x02;
+ public static final int SHARED = 0x04;
+ public static final int DEDICATED_ONE_ISTO_ONE = 0x08;
+ public static final int DEDICATED_ONE_PLUS_ONE = 0x10;
+ public static final int ENHANCED = 0x20;
+
+ /* Link Protection type flags */
+ private final boolean bExtraTraffic;
+ private final boolean bUnprotected;
+ private final boolean bShared;
+ private final boolean bDedOneIstoOne;
+ private final boolean bDedOnePlusOne;
+ private final boolean bEnhanced;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param bExtraTraffic Extra Traffic
+ * @param bUnprotected Unprotected
+ * @param bShared Shared
+ * @param bDedOneIstoOne Dedicated 1:1
+ * @param bDedOnePlusOne Dedicated 1+1
+ * @param bEnhanced Enhanced
+ */
+ private BgpLinkAttrProtectionType(boolean bExtraTraffic,
+ boolean bUnprotected,
+ boolean bShared, boolean bDedOneIstoOne,
+ boolean bDedOnePlusOne, boolean bEnhanced) {
+ this.bExtraTraffic = bExtraTraffic;
+ this.bUnprotected = bUnprotected;
+ this.bShared = bShared;
+ this.bDedOneIstoOne = bDedOneIstoOne;
+ this.bDedOnePlusOne = bDedOnePlusOne;
+ this.bEnhanced = bEnhanced;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param bExtraTraffic Extra Traffic
+ * @param bUnprotected Unprotected
+ * @param bShared Shared
+ * @param bDedOneIstoOne Dedicated 1:1
+ * @param bDedOnePlusOne Dedicated 1+1
+ * @param bEnhanced Enhanced
+ * @return object of BgpLinkAttrProtectionType
+ */
+ public static BgpLinkAttrProtectionType of(boolean bExtraTraffic,
+ boolean bUnprotected,
+ boolean bShared,
+ boolean bDedOneIstoOne,
+ boolean bDedOnePlusOne,
+ boolean bEnhanced) {
+ return new BgpLinkAttrProtectionType(bExtraTraffic, bUnprotected,
+ bShared, bDedOneIstoOne,
+ bDedOnePlusOne, bEnhanced);
+ }
+
+ /**
+ * Reads the BGP link attributes protection type.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrProtectionType
+ * @throws BgpParseException while parsing BgpLinkAttrProtectionType
+ */
+ public static BgpLinkAttrProtectionType read(ChannelBuffer cb)
+ throws BgpParseException {
+ short linkProtectionType;
+ byte higherByte;
+ short lsAttrLength = cb.readShort();
+
+ boolean bExtraTraffic;
+ boolean bUnprotected;
+ boolean bShared;
+ boolean bDedOneIstoOne;
+ boolean bDedOnePlusOne;
+ boolean bEnhanced;
+
+ if ((lsAttrLength != LINK_PROTECTION_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ linkProtectionType = cb.readShort();
+ higherByte = (byte) (linkProtectionType >> 8);
+
+ bExtraTraffic = ((higherByte & (byte) EXTRA_TRAFFIC) == EXTRA_TRAFFIC);
+ bUnprotected = ((higherByte & (byte) UNPROTECTED) == UNPROTECTED);
+ bShared = ((higherByte & (byte) SHARED) == SHARED);
+ bDedOneIstoOne = ((higherByte & (byte) DEDICATED_ONE_ISTO_ONE) == DEDICATED_ONE_ISTO_ONE);
+ bDedOnePlusOne = ((higherByte & (byte) DEDICATED_ONE_PLUS_ONE) == DEDICATED_ONE_PLUS_ONE);
+ bEnhanced = ((higherByte & (byte) ENHANCED) == ENHANCED);
+
+ return BgpLinkAttrProtectionType.of(bExtraTraffic, bUnprotected,
+ bShared, bDedOneIstoOne,
+ bDedOnePlusOne, bEnhanced);
+ }
+
+ /**
+ * Returns ExtraTraffic Bit.
+ *
+ * @return ExtraTraffic Bit
+ */
+ public boolean extraTraffic() {
+ return bExtraTraffic;
+ }
+
+ /**
+ * Returns Unprotected Bit.
+ *
+ * @return Unprotected Bit
+ */
+ public boolean unprotected() {
+ return bUnprotected;
+ }
+
+ /**
+ * Returns Shared Bit.
+ *
+ * @return Shared Bit
+ */
+ public boolean shared() {
+ return bShared;
+ }
+
+ /**
+ * Returns DedOneIstoOne Bit.
+ *
+ * @return DedOneIstoOne Bit
+ */
+ public boolean dedOneIstoOne() {
+ return bDedOneIstoOne;
+ }
+
+ /**
+ * Returns DedOnePlusOne Bit.
+ *
+ * @return DedOnePlusOne Bit
+ */
+ public boolean dedOnePlusOne() {
+ return bDedOnePlusOne;
+ }
+
+ /**
+ * Returns Enhanced Bit.
+ *
+ * @return Enhanced Bit
+ */
+ public boolean enhanced() {
+ return bEnhanced;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRLINK_PROTECTIONTYPE;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(bExtraTraffic, bUnprotected, bShared,
+ bDedOneIstoOne, bDedOnePlusOne, bEnhanced);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrProtectionType) {
+ BgpLinkAttrProtectionType other = (BgpLinkAttrProtectionType) obj;
+ return Objects.equals(bExtraTraffic, other.bExtraTraffic)
+ && Objects.equals(bUnprotected, other.bUnprotected)
+ && Objects.equals(bShared, other.bShared)
+ && Objects.equals(bDedOneIstoOne, other.bDedOneIstoOne)
+ && Objects.equals(bDedOnePlusOne, other.bDedOnePlusOne)
+ && Objects.equals(bEnhanced, other.bEnhanced);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("bExtraTraffic", bExtraTraffic)
+ .add("bUnprotected", bUnprotected).add("bShared", bShared)
+ .add("bDedOneIstoOne", bDedOneIstoOne)
+ .add("bDedOnePlusOne", bDedOnePlusOne)
+ .add("bEnhanced", bEnhanced).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java
new file mode 100644
index 00000000..4a6f23f9
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrSrlg.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP link Shared Risk Link Group attribute.
+ */
+public class BgpLinkAttrSrlg implements BgpValueType {
+
+ public static final short ATTRNODE_SRLG = 1097;
+
+ /* Shared Risk Link Group */
+ private List<Integer> sRlg = new ArrayList<Integer>();
+
+ /**
+ * Constructor to initialize the date.
+ *
+ * @param sRlg Shared Risk link group data
+ */
+ public BgpLinkAttrSrlg(List<Integer> sRlg) {
+ this.sRlg = sRlg;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param sRlg Shared Risk link group data
+ * @return object of BgpLinkAttrSrlg
+ */
+ public static BgpLinkAttrSrlg of(ArrayList<Integer> sRlg) {
+ return new BgpLinkAttrSrlg(sRlg);
+ }
+
+ /**
+ * Reads the BGP link attributes Shared Risk link group data.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrSrlg
+ * @throws BgpParseException while parsing BgpLinkAttrSrlg
+ */
+ public static BgpLinkAttrSrlg read(ChannelBuffer cb)
+ throws BgpParseException {
+ int tempSrlg;
+ ArrayList<Integer> sRlg = new ArrayList<Integer>();
+
+ short lsAttrLength = cb.readShort();
+ int len = lsAttrLength / Integer.SIZE; // each element is of 4 octets
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < len; i++) {
+ tempSrlg = cb.readInt();
+ sRlg.add(new Integer(tempSrlg));
+ }
+
+ return BgpLinkAttrSrlg.of(sRlg);
+ }
+
+ /**
+ * Returns the Shared Risk link group data.
+ *
+ * @return array of Shared Risk link group data
+ */
+ public List<Integer> attrSrlg() {
+ return sRlg;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRNODE_SRLG;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(sRlg);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrSrlg) {
+ BgpLinkAttrSrlg other = (BgpLinkAttrSrlg) obj;
+ return Objects.equals(sRlg, other.sRlg);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues().add("sRlg", sRlg).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java
new file mode 100644
index 00000000..1ae7ecc5
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP link state Default TE metric link attribute.
+ */
+public class BgpLinkAttrTeDefaultMetric implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrTeDefaultMetric.class);
+
+ public static final int ATTRLINK_TEDEFAULTMETRIC = 1092;
+ public static final int TE_DATA_LEN = 4;
+
+ /* TE Default Metric */
+ private int linkTeMetric;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param linkTeMetric TE default metric
+ *
+ */
+ public BgpLinkAttrTeDefaultMetric(int linkTeMetric) {
+ this.linkTeMetric = linkTeMetric;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param linkTeMetric TE default metric
+ * @return object of BgpLinkAttrTeDefaultMetric
+ */
+ public static BgpLinkAttrTeDefaultMetric of(final int linkTeMetric) {
+ return new BgpLinkAttrTeDefaultMetric(linkTeMetric);
+ }
+
+ /**
+ * Reads the BGP link attributes of TE default metric.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrTeDefaultMetric
+ * @throws BgpParseException while parsing BgpLinkAttrTeDefaultMetric
+ */
+ public static BgpLinkAttrTeDefaultMetric read(ChannelBuffer cb)
+ throws BgpParseException {
+ int linkTeMetric;
+
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != TE_DATA_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ linkTeMetric = cb.readInt();
+
+ return new BgpLinkAttrTeDefaultMetric(linkTeMetric);
+ }
+
+ /**
+ * Returns the TE default metrics.
+ *
+ * @return link default metric
+ */
+ public int attrLinkDefTeMetric() {
+ return linkTeMetric;
+ }
+
+ @Override
+ public short getType() {
+ return ATTRLINK_TEDEFAULTMETRIC;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(linkTeMetric);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrTeDefaultMetric) {
+ BgpLinkAttrTeDefaultMetric other = (BgpLinkAttrTeDefaultMetric) obj;
+ return Objects.equals(linkTeMetric, other.linkTeMetric);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("linkTEMetric", linkTeMetric).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java
new file mode 100644
index 00000000..c927eea5
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrUnRsrvdLinkBandwidth.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP unreserved bandwidth attribute.
+ */
+public class BgpLinkAttrUnRsrvdLinkBandwidth implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpLinkAttrUnRsrvdLinkBandwidth.class);
+
+ public static final int MAX_BANDWIDTH_LEN = 4;
+ public static final int NO_OF_BITS = 8;
+ public static final int NO_OF_PRIORITY = 8;
+
+ public short sType;
+
+ /* ISIS administrative group */
+ private List<Float> maxUnResBandwidth = new ArrayList<Float>();
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param maxUnResBandwidth Maximum Unreserved bandwidth
+ * @param sType returns the tag value
+ */
+ public BgpLinkAttrUnRsrvdLinkBandwidth(List<Float> maxUnResBandwidth,
+ short sType) {
+ this.maxUnResBandwidth = maxUnResBandwidth;
+ this.sType = sType;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param linkPfxMetric Prefix Metric
+ * @param sType returns the tag value
+ * @return object of BgpLinkAttrUnRsrvdLinkBandwidth
+ */
+ public static BgpLinkAttrUnRsrvdLinkBandwidth of(List<Float> linkPfxMetric, short sType) {
+ return new BgpLinkAttrUnRsrvdLinkBandwidth(linkPfxMetric, sType);
+ }
+
+ /**
+ * Reads the BGP link attributes of Maximum link bandwidth.
+ *
+ * @param cb Channel buffer
+ * @return object of type BgpLinkAttrMaxLinkBandwidth
+ * @throws BgpParseException while parsing BgpLinkAttrMaxLinkBandwidth
+ */
+ public static BgpLinkAttrUnRsrvdLinkBandwidth read(ChannelBuffer cb,
+ short sType)
+ throws BgpParseException {
+ ArrayList<Float> maxUnResBandwidth = new ArrayList<Float>();
+ float tmp;
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != MAX_BANDWIDTH_LEN * NO_OF_PRIORITY)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < NO_OF_PRIORITY; i++) {
+ tmp = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS;
+ maxUnResBandwidth.add(new Float(tmp));
+ }
+
+ return BgpLinkAttrUnRsrvdLinkBandwidth.of(maxUnResBandwidth, sType);
+ }
+
+ /**
+ * Returns maximum unreserved bandwidth.
+ *
+ * @return unreserved bandwidth.
+ */
+ public List<Float> getLinkAttrUnRsrvdLinkBandwidth() {
+ return maxUnResBandwidth;
+ }
+
+ /**
+ * Parse the IEEE floating point notation and returns it in normal float.
+ *
+ * @param iVal IEEE floating point number
+ * @return normal float
+ */
+ static float ieeeToFloatRead(int iVal) {
+ iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
+ | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
+
+ return Float.intBitsToFloat(iVal);
+ }
+
+ @Override
+ public short getType() {
+ return this.sType;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(maxUnResBandwidth);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpLinkAttrUnRsrvdLinkBandwidth) {
+ BgpLinkAttrUnRsrvdLinkBandwidth other = (BgpLinkAttrUnRsrvdLinkBandwidth) obj;
+ return Objects.equals(maxUnResBandwidth, other.maxUnResBandwidth);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("maxUnResBandwidth", maxUnResBandwidth).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java
new file mode 100644
index 00000000..a2d7c57e
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrExtRouteTag.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2015 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.attr;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP prefix route Extended tag attribute.
+ */
+public class BgpPrefixAttrExtRouteTag implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPrefixAttrExtRouteTag.class);
+
+ public static final int ATTR_PREFIX_EXTROUTETAG = 1154;
+ public static final int ATTR_PREFIX_EXT_LEN = 8;
+
+ /* Prefix Route Tag */
+ private List<Long> pfxExtRouteTag = new ArrayList<Long>();
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param pfxExtRouteTag Extended route tag
+ */
+ public BgpPrefixAttrExtRouteTag(List<Long> pfxExtRouteTag) {
+ this.pfxExtRouteTag = checkNotNull(pfxExtRouteTag);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param pfxExtRouteTag Prefix Metric
+ * @return object of BgpPrefixAttrMetric
+ */
+ public static BgpPrefixAttrExtRouteTag of(ArrayList<Long> pfxExtRouteTag) {
+ return new BgpPrefixAttrExtRouteTag(pfxExtRouteTag);
+ }
+
+ /**
+ * Reads the Extended Tag.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpPrefixAttrExtRouteTag
+ * @throws BgpParseException while parsing BgpPrefixAttrExtRouteTag
+ */
+ public static BgpPrefixAttrExtRouteTag read(ChannelBuffer cb)
+ throws BgpParseException {
+ ArrayList<Long> pfxExtRouteTag = new ArrayList<Long>();
+ long temp;
+
+ short lsAttrLength = cb.readShort();
+ int len = lsAttrLength / ATTR_PREFIX_EXT_LEN;
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < len; i++) {
+ temp = cb.readLong();
+ pfxExtRouteTag.add(new Long(temp));
+ }
+
+ return new BgpPrefixAttrExtRouteTag(pfxExtRouteTag);
+ }
+
+ /**
+ * Returns Extended route tag.
+ *
+ * @return route tag
+ */
+ public List<Long> pfxExtRouteTag() {
+ return pfxExtRouteTag;
+ }
+
+ @Override
+ public short getType() {
+ return ATTR_PREFIX_EXTROUTETAG;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(pfxExtRouteTag);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpPrefixAttrExtRouteTag) {
+ BgpPrefixAttrExtRouteTag other = (BgpPrefixAttrExtRouteTag) obj;
+ return Objects.equals(pfxExtRouteTag, other.pfxExtRouteTag);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("pfxExtRouteTag", pfxExtRouteTag).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java
new file mode 100644
index 00000000..4e84191a
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP prefix IGP Flag attribute.
+ */
+public final class BgpPrefixAttrIgpFlags implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPrefixAttrIgpFlags.class);
+
+ public static final int ATTR_PREFIX_FLAGBIT = 1152;
+ public static final int ATTR_PREFIX_FLAG_LEN = 1;
+
+ public static final byte FIRST_BIT = (byte) 0x80;
+ public static final byte SECOND_BIT = 0x40;
+ public static final byte THIRD_BIT = 0x20;
+ public static final byte FOURTH_BIT = 0x01;
+
+ /* Prefix IGP flag bit TLV */
+ private final boolean bisisUpDownBit;
+ private final boolean bOspfNoUnicastBit;
+ private final boolean bOspfLclAddrBit;
+ private final boolean bOspfNSSABit;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param bisisUpDownBit IS-IS Up/Down Bit
+ * @param bOspfNoUnicastBit OSPF no unicast Bit
+ * @param bOspfLclAddrBit OSPF local address Bit
+ * @param bOspfNSSABit OSPF propagate NSSA Bit
+ */
+ BgpPrefixAttrIgpFlags(boolean bisisUpDownBit,
+ boolean bOspfNoUnicastBit,
+ boolean bOspfLclAddrBit, boolean bOspfNSSABit) {
+ this.bisisUpDownBit = bisisUpDownBit;
+ this.bOspfNoUnicastBit = bOspfNoUnicastBit;
+ this.bOspfLclAddrBit = bOspfLclAddrBit;
+ this.bOspfNSSABit = bOspfNSSABit;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param bisisUpDownBit IS-IS Up/Down Bit
+ * @param bOspfNoUnicastBit OSPF no unicast Bit
+ * @param bOspfLclAddrBit OSPF local address Bit
+ * @param bOspfNSSABit OSPF propagate NSSA Bit
+ * @return object of BgpPrefixAttrIGPFlags
+ */
+ public static BgpPrefixAttrIgpFlags of(final boolean bisisUpDownBit,
+ final boolean bOspfNoUnicastBit,
+ final boolean bOspfLclAddrBit,
+ final boolean bOspfNSSABit) {
+ return new BgpPrefixAttrIgpFlags(bisisUpDownBit, bOspfNoUnicastBit,
+ bOspfLclAddrBit, bOspfNSSABit);
+ }
+
+ /**
+ * Reads the IGP Flags.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpPrefixAttrIGPFlags
+ * @throws BgpParseException while parsing BgpPrefixAttrIGPFlags
+ */
+ public static BgpPrefixAttrIgpFlags read(ChannelBuffer cb)
+ throws BgpParseException {
+ boolean bisisUpDownBit = false;
+ boolean bOspfNoUnicastBit = false;
+ boolean bOspfLclAddrBit = false;
+ boolean bOspfNSSABit = false;
+
+ short lsAttrLength = cb.readShort();
+
+ if ((lsAttrLength != ATTR_PREFIX_FLAG_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ byte nodeFlagBits = cb.readByte();
+
+ bisisUpDownBit = ((nodeFlagBits & FIRST_BIT) == FIRST_BIT);
+ bOspfNoUnicastBit = ((nodeFlagBits & SECOND_BIT) == SECOND_BIT);
+ bOspfLclAddrBit = ((nodeFlagBits & THIRD_BIT) == THIRD_BIT);
+ bOspfNSSABit = ((nodeFlagBits & FOURTH_BIT) == FOURTH_BIT);
+
+ return BgpPrefixAttrIgpFlags.of(bisisUpDownBit, bOspfNoUnicastBit,
+ bOspfLclAddrBit, bOspfNSSABit);
+ }
+
+ /**
+ * Returns the IS-IS Up/Down Bit set or not.
+ *
+ * @return IS-IS Up/Down Bit set or not
+ */
+ public boolean isisUpDownBit() {
+ return bisisUpDownBit;
+ }
+
+ /**
+ * Returns the OSPF no unicast Bit set or not.
+ *
+ * @return OSPF no unicast Bit set or not
+ */
+ public boolean ospfNoUnicastBit() {
+ return bOspfNoUnicastBit;
+ }
+
+ /**
+ * Returns the OSPF local address Bit set or not.
+ *
+ * @return OSPF local address Bit set or not
+ */
+ public boolean ospfLclAddrBit() {
+ return bOspfLclAddrBit;
+ }
+
+ /**
+ * Returns the OSPF propagate NSSA Bit set or not.
+ *
+ * @return OSPF propagate NSSA Bit set or not
+ */
+ public boolean ospfNSSABit() {
+ return bOspfNSSABit;
+ }
+
+ @Override
+ public short getType() {
+ return ATTR_PREFIX_FLAGBIT;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(bisisUpDownBit, bOspfNoUnicastBit, bOspfLclAddrBit,
+ bOspfNSSABit);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpPrefixAttrIgpFlags) {
+ BgpPrefixAttrIgpFlags other = (BgpPrefixAttrIgpFlags) obj;
+ return Objects.equals(bisisUpDownBit, other.bisisUpDownBit)
+ && Objects.equals(bOspfNoUnicastBit,
+ other.bOspfNoUnicastBit)
+ && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit)
+ && Objects.equals(bOspfNSSABit, other.bOspfNSSABit);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("bisisUpDownBit", bisisUpDownBit)
+ .add("bOspfNoUnicastBit", bOspfNoUnicastBit)
+ .add("bOspfLclAddrBit", bOspfLclAddrBit)
+ .add("bOspfNSSABit", bOspfNSSABit).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java
new file mode 100644
index 00000000..1886102c
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetric.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP prefix metric attribute.
+ */
+public class BgpPrefixAttrMetric implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPrefixAttrMetric.class);
+
+ public static final int ATTR_PREFIX_METRIC = 1155;
+ public static final int ATTR_PREFIX_LEN = 4;
+
+ /* TE Default Metric */
+ private final int linkPfxMetric;
+
+ /**
+ * Constructor to initialize value.
+ *
+ * @param linkPfxMetric Prefix Metric
+ */
+ public BgpPrefixAttrMetric(int linkPfxMetric) {
+ this.linkPfxMetric = linkPfxMetric;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param linkPfxMetric Prefix Metric
+ * @return object of BgpPrefixAttrMetric
+ */
+ public static BgpPrefixAttrMetric of(final int linkPfxMetric) {
+ return new BgpPrefixAttrMetric(linkPfxMetric);
+ }
+
+ /**
+ * Reads the Prefix Metric.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpPrefixAttrMetric
+ * @throws BgpParseException while parsing BgpPrefixAttrMetric
+ */
+ public static BgpPrefixAttrMetric read(ChannelBuffer cb)
+ throws BgpParseException {
+ int linkPfxMetric;
+
+ short lsAttrLength = cb.readShort(); // 4 Bytes
+
+ if ((lsAttrLength != ATTR_PREFIX_LEN)
+ || (cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ linkPfxMetric = cb.readInt();
+
+ return BgpPrefixAttrMetric.of(linkPfxMetric);
+ }
+
+ /**
+ * Returns the Prefix Metric.
+ *
+ * @return Prefix Metric
+ */
+ public int attrPfxMetric() {
+ return linkPfxMetric;
+ }
+
+ @Override
+ public short getType() {
+ return ATTR_PREFIX_METRIC;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(linkPfxMetric);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpPrefixAttrMetric) {
+ BgpPrefixAttrMetric other = (BgpPrefixAttrMetric) obj;
+ return Objects.equals(linkPfxMetric, other.linkPfxMetric);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("linkPfxMetric", linkPfxMetric).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java
new file mode 100644
index 00000000..6f7a74bb
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Arrays;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP prefix opaque data attribute.
+ */
+public final class BgpPrefixAttrOpaqueData implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPrefixAttrOpaqueData.class);
+
+ public static final int ATTR_PREFIX_OPAQUEDATA = 1157;
+
+ /* Opaque Node Attribute */
+ private final byte[] opaquePrefixAttribute;
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param opaquePrefixAttribute opaque prefix data
+ */
+ public BgpPrefixAttrOpaqueData(byte[] opaquePrefixAttribute) {
+ this.opaquePrefixAttribute = Arrays
+ .copyOf(opaquePrefixAttribute, opaquePrefixAttribute.length);
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param opaquePrefixAttribute opaque prefix data
+ * @return object of BgpPrefixAttrOpaqueData
+ */
+ public static BgpPrefixAttrOpaqueData of(final byte[] opaquePrefixAttribute) {
+ return new BgpPrefixAttrOpaqueData(opaquePrefixAttribute);
+ }
+
+ /**
+ * Reads the Opaque Prefix Attribute.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpPrefixAttrOpaqueData
+ * @throws BgpParseException while parsing BgpPrefixAttrOpaqueData
+ */
+ public static BgpPrefixAttrOpaqueData read(ChannelBuffer cb)
+ throws BgpParseException {
+ byte[] opaquePrefixAttribute;
+
+ short lsAttrLength = cb.readShort();
+ opaquePrefixAttribute = new byte[lsAttrLength];
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ cb.readBytes(opaquePrefixAttribute);
+
+ return BgpPrefixAttrOpaqueData.of(opaquePrefixAttribute);
+ }
+
+ /**
+ * Returns the Opaque prefix attribute name.
+ *
+ * @return opaque prefix name
+ */
+ public byte[] getOpaquePrefixAttribute() {
+ return opaquePrefixAttribute;
+ }
+
+ @Override
+ public short getType() {
+ return ATTR_PREFIX_OPAQUEDATA;
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(opaquePrefixAttribute);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpPrefixAttrOpaqueData) {
+ BgpPrefixAttrOpaqueData other = (BgpPrefixAttrOpaqueData) obj;
+ return Arrays.equals(opaquePrefixAttribute,
+ other.opaquePrefixAttribute);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("opaquePrefixAttribute", getOpaquePrefixAttribute())
+ .toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java
new file mode 100644
index 00000000..4e9db1ee
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddr.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.Ip6Address;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP prefix OSPF Forwarding address attribute.
+ */
+public class BgpPrefixAttrOspfFwdAddr implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPrefixAttrOspfFwdAddr.class);
+
+ public static final int ATTR_PREFIX_OSPFFWDADDR = 1156;
+ public static final int IPV4_LEN = 4;
+ public static final int IPV6_LEN = 16;
+
+ /* OSPF Forwarding Address */
+ private final short lsAttrLength;
+ private final Ip4Address ip4RouterId;
+ private final Ip6Address ip6RouterId;
+
+ /**
+ * Constructor to initialize the value.
+ *
+ * @param lsAttrLength length of the IP address
+ * @param ip4RouterId Valid IPV4 address if length is 4 else null
+ * @param ip6RouterId Valid IPV6 address if length is 16 else null
+ */
+ public BgpPrefixAttrOspfFwdAddr(short lsAttrLength, Ip4Address ip4RouterId,
+ Ip6Address ip6RouterId) {
+ this.lsAttrLength = lsAttrLength;
+ this.ip4RouterId = ip4RouterId;
+ this.ip6RouterId = ip6RouterId;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param lsAttrLength length of the IP address
+ * @param ip4RouterId Valid IPV4 address if length is 4 else null
+ * @param ip6RouterId Valid IPV6 address if length is 16 else null
+ * @return object of BgpPrefixAttrOspfFwdAddr
+ */
+ public static BgpPrefixAttrOspfFwdAddr of(final short lsAttrLength,
+ final Ip4Address ip4RouterId,
+ final Ip6Address ip6RouterId) {
+ return new BgpPrefixAttrOspfFwdAddr(lsAttrLength, ip4RouterId,
+ ip6RouterId);
+ }
+
+ /**
+ * Reads the OSPF Forwarding Address.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpPrefixAttrOSPFFwdAddr
+ * @throws BgpParseException while parsing BgpPrefixAttrOspfFwdAddr
+ */
+ public static BgpPrefixAttrOspfFwdAddr read(ChannelBuffer cb)
+ throws BgpParseException {
+ short lsAttrLength;
+ byte[] ipBytes;
+ Ip4Address ip4RouterId = null;
+ Ip6Address ip6RouterId = null;
+
+ lsAttrLength = cb.readShort();
+ ipBytes = new byte[lsAttrLength];
+
+ if ((cb.readableBytes() < lsAttrLength)) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ cb.readBytes(ipBytes);
+
+ if (IPV4_LEN == lsAttrLength) {
+ ip4RouterId = Ip4Address.valueOf(ipBytes);
+ } else if (IPV6_LEN == lsAttrLength) {
+ ip6RouterId = Ip6Address.valueOf(ipBytes);
+ }
+
+ return BgpPrefixAttrOspfFwdAddr.of(lsAttrLength, ip4RouterId,
+ ip6RouterId);
+ }
+
+ /**
+ * Returns IPV4 Address of OSPF forwarding address.
+ *
+ * @return IPV4 address
+ */
+ public Ip4Address ospfv4FwdAddr() {
+ return ip4RouterId;
+ }
+
+ /**
+ * Returns IPV6 Address of OSPF forwarding address.
+ *
+ * @return IPV6 address
+ */
+ public Ip6Address ospfv6FwdAddr() {
+ return ip6RouterId;
+ }
+
+ /**
+ * Returns OSPF forwarding address length.
+ *
+ * @return length of the ip address
+ */
+ public short ospfFwdAddrLen() {
+ return lsAttrLength;
+ }
+
+ @Override
+ public short getType() {
+ return ATTR_PREFIX_OSPFFWDADDR;
+ }
+
+ @Override
+ public int hashCode() {
+ if (IPV4_LEN == lsAttrLength) {
+ return Objects.hash(ip4RouterId);
+ } else {
+ return Objects.hash(ip6RouterId);
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpPrefixAttrOspfFwdAddr) {
+ BgpPrefixAttrOspfFwdAddr other = (BgpPrefixAttrOspfFwdAddr) obj;
+ if (IPV4_LEN == lsAttrLength) {
+ return Objects.equals(ip4RouterId, other.ip4RouterId);
+ } else {
+ return Objects.equals(ip6RouterId, other.ip6RouterId);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ if (IPV4_LEN == lsAttrLength) {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("ip4RouterId", ip4RouterId).toString();
+ } else {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("ip6RouterId", ip6RouterId).toString();
+ }
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
new file mode 100644
index 00000000..3894c003
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2015 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.attr;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.bgpio.exceptions.BgpParseException;
+import org.onosproject.bgpio.types.BgpErrorType;
+import org.onosproject.bgpio.types.BgpValueType;
+import org.onosproject.bgpio.util.Validation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Implements BGP prefix route tag attribute.
+ */
+public class BgpPrefixAttrRouteTag implements BgpValueType {
+
+ protected static final Logger log = LoggerFactory
+ .getLogger(BgpPrefixAttrRouteTag.class);
+
+ public static final short ATTR_PREFIX_ROUTETAG = 1153;
+
+ /* Prefix Route Tag */
+ private List<Integer> pfxRouteTag = new ArrayList<Integer>();
+
+ /**
+ * Constructor to initialize the values.
+ *
+ * @param pfxRouteTag prefix route tag
+ */
+ public BgpPrefixAttrRouteTag(List<Integer> pfxRouteTag) {
+ this.pfxRouteTag = pfxRouteTag;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param pfxRouteTag Prefix Metric
+ * @return object of BgpPrefixAttrRouteTag
+ */
+ public static BgpPrefixAttrRouteTag of(ArrayList<Integer> pfxRouteTag) {
+ return new BgpPrefixAttrRouteTag(pfxRouteTag);
+ }
+
+ /**
+ * Reads the Route Tag.
+ *
+ * @param cb ChannelBuffer
+ * @return object of BgpPrefixAttrRouteTag
+ * @throws BgpParseException while parsing BgpPrefixAttrRouteTag
+ */
+ public static BgpPrefixAttrRouteTag read(ChannelBuffer cb)
+ throws BgpParseException {
+ int tmp;
+ ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>();
+
+ short lsAttrLength = cb.readShort();
+ int len = lsAttrLength / Integer.SIZE;
+
+ if (cb.readableBytes() < lsAttrLength) {
+ Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
+ BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
+ lsAttrLength);
+ }
+
+ for (int i = 0; i < len; i++) {
+ tmp = cb.readInt();
+ pfxRouteTag.add(new Integer(tmp));
+ }
+
+ return BgpPrefixAttrRouteTag.of(pfxRouteTag);
+ }
+
+ /**
+ * Returns the prefix route tag.
+ *
+ * @return route tag
+ */
+ public List<Integer> getPfxRouteTag() {
+ return pfxRouteTag;
+ }
+
+ @Override
+ public short getType() {
+ return ATTR_PREFIX_ROUTETAG;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(pfxRouteTag);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj instanceof BgpPrefixAttrRouteTag) {
+ BgpPrefixAttrRouteTag other = (BgpPrefixAttrRouteTag) obj;
+ return Objects.equals(pfxRouteTag, other.pfxRouteTag);
+ }
+ return false;
+ }
+
+ @Override
+ public int write(ChannelBuffer cb) {
+ // TODO This will be implemented in the next version
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("pfxRouteTag", pfxRouteTag).toString();
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/package-info.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/package-info.java
new file mode 100755
index 00000000..e2a74dbc
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 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.
+ */
+
+/**
+ * Implementation of BGP Link state attribute Tlvs.
+ */
+package org.onosproject.bgpio.types.attr;
diff --git a/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/package-info.java b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/package-info.java
new file mode 100755
index 00000000..1f2ed95e
--- /dev/null
+++ b/framework/src/onos/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 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.
+ */
+
+/**
+ * Implementation of Tlvs, Attributes and Descriptors.
+ */
+package org.onosproject.bgpio.types;