diff options
author | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-05 14:00:42 -0800 |
---|---|---|
committer | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-05 14:00:42 -0800 |
commit | b34f82bf11934fc6b938ef997d536a7ccea76c36 (patch) | |
tree | 10559ebf65962abb741883ca9d23aec241ced504 /framework/src/onos/bgp/bgpio/src/main | |
parent | 2cdecb8c41956d7dd8ab5d59591ebc21f3c64a9e (diff) |
Updates ONOS tree to checkin id ca9cc8e28eba18da77f4fa021fb7c3a3f76e5d44
upstream.
Change-Id: I49f8e41733afea8101ec50c0102213c8d18949ae
Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/bgp/bgpio/src/main')
6 files changed, 641 insertions, 50 deletions
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java index a8c242b4..bf5d05f4 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java @@ -72,13 +72,6 @@ public interface BGPOpenMsg extends BGPMessage { BGPOpenMsg build() throws BGPParseException; /** - * Returns hold time of Open Message. - * - * @return hold time of Open Message - */ - short getHoldTime(); - - /** * Sets hold time in Open Message and return its builder. * * @param holdtime hold timer value in open message @@ -87,13 +80,6 @@ public interface BGPOpenMsg extends BGPMessage { Builder setHoldTime(short holdtime); /** - * Returns as number of Open Message. - * - * @return as number of Open Message - */ - short getAsNumber(); - - /** * Sets AS number in Open Message and return its builder. * * @param asNumber as number in open message @@ -102,13 +88,6 @@ public interface BGPOpenMsg extends BGPMessage { Builder setAsNumber(short asNumber); /** - * Returns BGP Identifier of Open Message. - * - * @return BGP Identifier of Open Message - */ - int getBgpId(); - - /** * Sets BGP Identifier in Open Message and return its builder. * * @param bgpId BGP Identifier in open message @@ -117,13 +96,6 @@ public interface BGPOpenMsg extends BGPMessage { Builder setBgpId(int bgpId); /** - * Returns capabilities of Open Message. - * - * @return capabilities of Open Message - */ - LinkedList<BGPValueType> getCapabilityTlv(); - - /** * Sets capabilities in Open Message and return its builder. * * @param capabilityTlv capabilities in open message diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPLinkLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPLinkLSIdentifier.java new file mode 100755 index 00000000..3229cc11 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPLinkLSIdentifier.java @@ -0,0 +1,252 @@ +/* + * 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.protocol.link_state; + +import java.util.Iterator; +import java.util.LinkedList; +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.types.IPv4AddressTlv; +import org.onosproject.bgpio.types.IPv6AddressTlv; +import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; +import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId; +import org.onosproject.bgpio.util.UnSupportedAttribute; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +/** + * Implementation of local node descriptors, remote node descriptors and link descriptors. + */ +public class BGPLinkLSIdentifier { + private static final Logger log = LoggerFactory.getLogger(BGPLinkLSIdentifier.class); + public static final short IPV4_INTERFACE_ADDRESS_TYPE = 259; + public static final short IPV4_NEIGHBOR_ADDRESS_TYPE = 260; + public static final short IPV6_INTERFACE_ADDRESS_TYPE = 261; + public static final short IPV6_NEIGHBOR_ADDRESS_TYPE = 262; + public static final int TYPE_AND_LEN = 4; + + private NodeDescriptors localNodeDescriptors; + private NodeDescriptors remoteNodeDescriptors; + private List<BGPValueType> linkDescriptor; + + /** + * Initialize fields. + */ + public BGPLinkLSIdentifier() { + this.localNodeDescriptors = null; + this.remoteNodeDescriptors = null; + this.linkDescriptor = null; + } + + /** + * Constructors to initialize parameters. + * + * @param localNodeDescriptors local node descriptors + * @param remoteNodeDescriptors remote node descriptors + * @param linkDescriptor link descriptors + */ + public BGPLinkLSIdentifier(NodeDescriptors localNodeDescriptors, NodeDescriptors remoteNodeDescriptors, + LinkedList<BGPValueType> linkDescriptor) { + this.localNodeDescriptors = Preconditions.checkNotNull(localNodeDescriptors); + this.remoteNodeDescriptors = Preconditions.checkNotNull(remoteNodeDescriptors); + this.linkDescriptor = Preconditions.checkNotNull(linkDescriptor); + } + + /** + * Reads channel buffer and parses link identifier. + * + * @param cb ChannelBuffer + * @param protocolId in linkstate nlri + * @return object of BGPLinkLSIdentifier + * @throws BGPParseException while parsing link identifier + */ + public static BGPLinkLSIdentifier parseLinkIdendifier(ChannelBuffer cb, byte protocolId) throws BGPParseException { + //Parse local node descriptor + NodeDescriptors localNodeDescriptors = new NodeDescriptors(); + localNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.LOCAL_NODE_DES_TYPE, protocolId); + + //Parse remote node descriptor + NodeDescriptors remoteNodeDescriptors = new NodeDescriptors(); + remoteNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.REMOTE_NODE_DES_TYPE, protocolId); + + //Parse link descriptor + LinkedList<BGPValueType> linkDescriptor = new LinkedList<>(); + linkDescriptor = parseLinkDescriptors(cb); + return new BGPLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, linkDescriptor); + } + + /** + * Parses Local/Remote node descriptors. + * + * @param cb ChannelBuffer + * @param desType descriptor type + * @param protocolId protocol identifier + * @return object of NodeDescriptors + * @throws BGPParseException while parsing Local/Remote node descriptors + */ + public static NodeDescriptors parseNodeDescriptors(ChannelBuffer cb, short desType, byte protocolId) + throws BGPParseException { + ChannelBuffer tempBuf = cb; + short type = cb.readShort(); + short length = cb.readShort(); + if (cb.readableBytes() < length) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, + tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN)); + } + NodeDescriptors nodeIdentifier = new NodeDescriptors(); + ChannelBuffer tempCb = cb.readBytes(length); + + if (type == desType) { + nodeIdentifier = NodeDescriptors.read(tempCb, length, desType, protocolId); + } else { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + return nodeIdentifier; + } + + /** + * Parses link descriptors. + * + * @param cb ChannelBuffer + * @return list of link descriptors + * @throws BGPParseException while parsing link descriptors + */ + public static LinkedList<BGPValueType> parseLinkDescriptors(ChannelBuffer cb) throws BGPParseException { + LinkedList<BGPValueType> linkDescriptor = new LinkedList<>(); + BGPValueType tlv = null; + int count = 0; + + while (cb.readableBytes() > 0) { + ChannelBuffer tempBuf = cb; + short type = cb.readShort(); + short length = cb.readShort(); + if (cb.readableBytes() < length) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, + tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN)); + } + ChannelBuffer tempCb = cb.readBytes(length); + switch (type) { + case LinkLocalRemoteIdentifiersTlv.TYPE: + tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb); + break; + case IPV4_INTERFACE_ADDRESS_TYPE: + tlv = IPv4AddressTlv.read(tempCb, IPV4_INTERFACE_ADDRESS_TYPE); + break; + case IPV4_NEIGHBOR_ADDRESS_TYPE: + tlv = IPv4AddressTlv.read(tempCb, IPV4_NEIGHBOR_ADDRESS_TYPE); + break; + case IPV6_INTERFACE_ADDRESS_TYPE: + tlv = IPv6AddressTlv.read(tempCb, IPV6_INTERFACE_ADDRESS_TYPE); + break; + case IPV6_NEIGHBOR_ADDRESS_TYPE: + tlv = IPv6AddressTlv.read(tempCb, IPV6_NEIGHBOR_ADDRESS_TYPE); + break; + case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY: + tlv = BgpAttrNodeMultiTopologyId.read(tempCb); + count = count++; + //MultiTopologyId TLV cannot repeat more than once + if (count > 1) { + //length + 4 implies data contains type, length and value + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length + + TYPE_AND_LEN)); + } + break; + default: + UnSupportedAttribute.skipBytes(tempCb, length); + } + linkDescriptor.add(tlv); + } + return linkDescriptor; + } + + /** + * Returns local node descriptors. + * + * @return local node descriptors + */ + public NodeDescriptors localNodeDescriptors() { + return this.localNodeDescriptors; + } + + /** + * Returns remote node descriptors. + * + * @return remote node descriptors + */ + public NodeDescriptors remoteNodeDescriptors() { + return this.remoteNodeDescriptors; + } + + /** + * Returns link descriptors. + * + * @return link descriptors + */ + public List<BGPValueType> linkDescriptors() { + return this.linkDescriptor; + } + + @Override + public int hashCode() { + return Objects.hash(linkDescriptor, localNodeDescriptors, remoteNodeDescriptors); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof BGPLinkLSIdentifier) { + int countObjSubTlv = 0; + int countOtherSubTlv = 0; + boolean isCommonSubTlv = true; + BGPLinkLSIdentifier other = (BGPLinkLSIdentifier) obj; + Iterator<BGPValueType> objListIterator = other.linkDescriptor.iterator(); + countOtherSubTlv = other.linkDescriptor.size(); + countObjSubTlv = linkDescriptor.size(); + if (countObjSubTlv != countOtherSubTlv) { + return false; + } else { + while (objListIterator.hasNext() && isCommonSubTlv) { + BGPValueType subTlv = objListIterator.next(); + isCommonSubTlv = Objects.equals(linkDescriptor.contains(subTlv), + other.linkDescriptor.contains(subTlv)); + } + return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors) + && Objects.equals(this.remoteNodeDescriptors, other.remoteNodeDescriptors); + } + } + return false; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("localNodeDescriptors", localNodeDescriptors) + .add("remoteNodeDescriptors", remoteNodeDescriptors) + .add("linkDescriptor", linkDescriptor) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java index b50342d6..fccbf5f7 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java @@ -311,8 +311,8 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg { if (this.isLargeAsCapabilityTlvSet) { BGPValueType tlv; - int iValue = this.getAsNumber(); - tlv = new FourOctetAsNumCapabilityTlv(iValue); + int value = this.asNumber; + tlv = new FourOctetAsNumCapabilityTlv(value); this.capabilityTlv.add(tlv); } @@ -333,26 +333,6 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg { } @Override - public short getHoldTime() { - return this.holdTime; - } - - @Override - public short getAsNumber() { - return this.asNumber; - } - - @Override - public int getBgpId() { - return this.bgpId; - } - - @Override - public LinkedList<BGPValueType> getCapabilityTlv() { - return this.capabilityTlv; - } - - @Override public Builder setHoldTime(short holdTime) { this.holdTime = holdTime; this.isHoldTimeSet = true; diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java new file mode 100644 index 00000000..d5f03268 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java @@ -0,0 +1,128 @@ +/* + * 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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +/** + * Provides Implementation of IPv4AddressTlv. + */ +public class IPv4AddressTlv implements BGPValueType { + private static final Logger log = LoggerFactory.getLogger(IPv4AddressTlv.class); + 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 getValue() { + 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 { + //TODO: use Validation.toInetAddress once Validation is merged + InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH); + 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 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/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java new file mode 100644 index 00000000..65b7c16d --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java @@ -0,0 +1,128 @@ +/* + * 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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +/** + * Provides Implementation of IPv6AddressTlv. + */ +public class IPv6AddressTlv implements BGPValueType { + private static final Logger log = LoggerFactory.getLogger(IPv6AddressTlv.class); + 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 getValue() { + 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 { + //TODO: use Validation.toInetAddress once Validation is merged + InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH); + 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 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/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java new file mode 100644 index 00000000..988925f5 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Provides Implementation of Link Local/Remote IdentifiersTlv. + */ +public class LinkLocalRemoteIdentifiersTlv implements BGPValueType { + private static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class); + 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 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 |