From e5df26295703f2f8f5f9b9ee406407a5684b8122 Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Fri, 13 Nov 2015 16:06:48 -0800 Subject: ONOS commit id 710293f3afa03540a1fd3be038da0ea6a488765c Change-Id: I66c2370960d7597bdbaf7bf58defca3e864c4215 Signed-off-by: Ashlee Young --- .../onosproject/bgpio/protocol/BgpLinkLsNlri.java | 47 ++++ .../onosproject/bgpio/protocol/BgpUpdateMsg.java | 48 ++++ .../bgpio/protocol/ver4/BgpUpdateMsgVer4.java | 285 +++++++++++++++++++++ .../org/onosproject/bgpio/types/MpReachNlri.java | 221 ++++++++++++++++ .../org/onosproject/bgpio/types/MpUnReachNlri.java | 203 +++++++++++++++ .../types/attr/BgpLinkAttrIsIsAdminstGrp.java | 130 ++++++++++ .../types/attr/BgpLinkAttrMaxLinkBandwidth.java | 150 +++++++++++ .../bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java | 133 ++++++++++ .../bgp/BgpLinkAttrMaxLinkBandwidthTest.java | 44 ++++ .../bgp/BgpPrefixAttrOpaqueDataTest.java | 42 +++ .../org/onosproject/bgpio/types/LocalPrefTest.java | 40 +++ .../java/org/onosproject/bgpio/types/MedTest.java | 40 +++ 12 files changed, 1383 insertions(+) create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java create mode 100644 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java create mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java (limited to 'framework/src/onos/bgp/bgpio') diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java new file mode 100644 index 00000000..1445c763 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.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.protocol; + +import java.util.List; + +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; + +/** + * Abstraction of an entity providing BGP-LS Link NLRI. + */ +public interface BgpLinkLsNlri extends BGPLSNlri { + /** + * Returns local node descriptors. + * + * @return local node descriptors + */ + NodeDescriptors getLocalNodeDescriptors(); + + /** + * Returns remote node descriptors. + * + * @return remote node descriptors + */ + NodeDescriptors getRemoteNodeDescriptors(); + + /** + * Returns link descriptors. + * + * @return link descriptors + */ + List getLinkDescriptors(); +} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java new file mode 100644 index 00000000..969936c8 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java @@ -0,0 +1,48 @@ +/* + * 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; + +import java.util.List; + +import org.onlab.packet.IpPrefix; +import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes; + +/** + * Abstraction of an entity providing BGP Update Message. + */ +public interface BgpUpdateMsg extends BGPMessage { + /** + * Returns path attributes in BGP Update Message. + * + * @return path attributes in BGP Update Message + */ + BgpPathAttributes bgpPathAttributes(); + + /** + * Returns withdrawn Routes. + * + * @return withdrawn Routes + */ + List withdrawnRoutes(); + + /** + * Returns NLRI list of prefix. + * + * @return NLRI list of prefix + */ + List nlri(); +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java new file mode 100644 index 00000000..9f4cf9b9 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java @@ -0,0 +1,285 @@ +/* + * 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.ver4; + +import java.util.LinkedList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onlab.packet.IpPrefix; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPMessageReader; +import org.onosproject.bgpio.protocol.BGPType; +import org.onosproject.bgpio.protocol.BgpUpdateMsg; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPHeader; +import org.onosproject.bgpio.util.Validation; +import org.onosproject.bgpio.protocol.BGPVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * BGP Update Message: UPDATE messages are used to transfer routing information + * between BGP peers. The information in the UPDATE message is used by core to + * construct a graph + */ +public class BgpUpdateMsgVer4 implements BgpUpdateMsg { + + /* 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 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Withdrawn Routes Length (2 octets) | + +-----------------------------------------------------+ + | Withdrawn Routes (variable) | + +-----------------------------------------------------+ + | Total Path Attribute Length (2 octets) | + +-----------------------------------------------------+ + | Path Attributes (variable) | + +-----------------------------------------------------+ + | Network Layer Reachability Information (variable) | + +-----------------------------------------------------+ + REFERENCE : RFC 4271 + */ + + protected static final Logger log = LoggerFactory + .getLogger(BgpUpdateMsgVer4.class); + + public static final byte PACKET_VERSION = 4; + //Withdrawn Routes Length(2) + Total Path Attribute Length(2) + public static final int PACKET_MINIMUM_LENGTH = 4; + public static final int BYTE_IN_BITS = 8; + public static final int MIN_LEN_AFTER_WITHDRW_ROUTES = 2; + public static final int MINIMUM_COMMON_HEADER_LENGTH = 19; + public static final BGPType MSG_TYPE = BGPType.UPDATE; + public static final BgpUpdateMsgVer4.Reader READER = new Reader(); + + private List withdrawnRoutes; + private BgpPathAttributes bgpPathAttributes; + private BGPHeader bgpHeader; + private List nlri; + + /** + * Constructor to initialize parameters for BGP Update message. + * + * @param bgpHeader in Update message + * @param withdrawnRoutes withdrawn routes + * @param bgpPathAttributes BGP Path attributes + * @param nlri Network Layer Reachability Information + */ + public BgpUpdateMsgVer4(BGPHeader bgpHeader, List withdrawnRoutes, + BgpPathAttributes bgpPathAttributes, List nlri) { + this.bgpHeader = bgpHeader; + this.withdrawnRoutes = withdrawnRoutes; + this.bgpPathAttributes = bgpPathAttributes; + this.nlri = nlri; + } + + /** + * Reader reads BGP Update Message from the channel buffer. + */ + static class Reader implements BGPMessageReader { + + @Override + public BgpUpdateMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader) + throws BGPParseException { + + if (cb.readableBytes() != (bgpHeader.getLength() - MINIMUM_COMMON_HEADER_LENGTH)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.BAD_MESSAGE_LENGTH, bgpHeader.getLength()); + } + + LinkedList withDrwRoutes = new LinkedList<>(); + LinkedList nlri = new LinkedList<>(); + BgpPathAttributes bgpPathAttributes = new BgpPathAttributes(); + // Reading Withdrawn Routes Length + Short withDrwLen = cb.readShort(); + + if (cb.readableBytes() < withDrwLen) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + ChannelBuffer tempCb = cb.readBytes(withDrwLen); + if (withDrwLen != 0) { + // Parsing WithdrawnRoutes + withDrwRoutes = parseWithdrawnRoutes(tempCb); + } + if (cb.readableBytes() < MIN_LEN_AFTER_WITHDRW_ROUTES) { + log.debug("Bgp Path Attribute len field not present"); + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + + // Reading Total Path Attribute Length + short totPathAttrLen = cb.readShort(); + int len = withDrwLen + totPathAttrLen + PACKET_MINIMUM_LENGTH; + if (len > bgpHeader.getLength()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + if (totPathAttrLen != 0) { + // Parsing BGPPathAttributes + if (cb.readableBytes() < totPathAttrLen) { + Validation + .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + tempCb = cb.readBytes(totPathAttrLen); + bgpPathAttributes = BgpPathAttributes.read(tempCb); + } + if (cb.readableBytes() > 0) { + // Parsing NLRI + nlri = parseNlri(cb); + } + return new BgpUpdateMsgVer4(bgpHeader, withDrwRoutes, + bgpPathAttributes, nlri); + } + } + + /** + * Parses NLRI from channel buffer. + * + * @param cb channelBuffer + * @return list of IP Prefix + * @throws BGPParseException while parsing NLRI + */ + public static LinkedList parseNlri(ChannelBuffer cb) + throws BGPParseException { + LinkedList nlri = new LinkedList<>(); + while (cb.readableBytes() > 0) { + int length = cb.readByte(); + IpPrefix ipPrefix; + if (length == 0) { + byte[] prefix = new byte[] {0}; + ipPrefix = Validation.bytesToPrefix(prefix, length); + nlri.add(ipPrefix); + } else { + int len = length / BYTE_IN_BITS; + int reminder = length % BYTE_IN_BITS; + if (reminder > 0) { + len = len + 1; + } + if (cb.readableBytes() < len) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + byte[] prefix = new byte[len]; + cb.readBytes(prefix, 0, len); + ipPrefix = Validation.bytesToPrefix(prefix, length); + nlri.add(ipPrefix); + } + } + return nlri; + } + + /** + * Parsing withdrawn routes from channel buffer. + * + * @param cb channelBuffer + * @return list of IP prefix + * @throws BGPParseException while parsing withdrawn routes + */ + public static LinkedList parseWithdrawnRoutes(ChannelBuffer cb) + throws BGPParseException { + LinkedList withDrwRoutes = new LinkedList<>(); + while (cb.readableBytes() > 0) { + int length = cb.readByte(); + IpPrefix ipPrefix; + if (length == 0) { + byte[] prefix = new byte[] {0}; + ipPrefix = Validation.bytesToPrefix(prefix, length); + withDrwRoutes.add(ipPrefix); + } else { + int len = length / BYTE_IN_BITS; + int reminder = length % BYTE_IN_BITS; + if (reminder > 0) { + len = len + 1; + } + if (cb.readableBytes() < len) { + Validation + .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + byte[] prefix = new byte[len]; + cb.readBytes(prefix, 0, len); + ipPrefix = Validation.bytesToPrefix(prefix, length); + withDrwRoutes.add(ipPrefix); + } + } + return withDrwRoutes; + } + + @Override + public BGPVersion getVersion() { + return BGPVersion.BGP_4; + } + + @Override + public BGPType getType() { + return BGPType.UPDATE; + } + + @Override + public void writeTo(ChannelBuffer channelBuffer) throws BGPParseException { + //Not to be implemented as of now + } + + @Override + public BgpPathAttributes bgpPathAttributes() { + return this.bgpPathAttributes; + } + + @Override + public List withdrawnRoutes() { + return withdrawnRoutes; + } + + @Override + public List nlri() { + return nlri; + } + + @Override + public BGPHeader getHeader() { + return this.bgpHeader; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .omitNullValues() + .add("bgpHeader", bgpHeader) + .add("withDrawnRoutes", withdrawnRoutes) + .add("nlri", nlri) + .add("bgpPathAttributes", bgpPathAttributes) + .toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java new file mode 100644 index 00000000..90a1cc6b --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java @@ -0,0 +1,221 @@ +/* + * 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.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 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 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 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 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(); + //TODO: use Validation.toInetAddress once Validation is merged + InetAddress ipAddress = (InetAddress) cb.readBytes(nextHopLen); + 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 LINK_NLRITYPE: + //TODO: To be merged later + break; + case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE: + bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi); + break; + default: + log.debug("nlriType not supported" + nlriType); + } + mpReachNlri.add(bgpLSNlri); + } + } else { + //TODO: check with the values got from capability + 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(); + } +} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java new file mode 100644 index 00000000..3efed95c --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java @@ -0,0 +1,203 @@ +/* + * 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.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 { + + protected 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 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 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 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 LINK_NLRITYPE: + //TODO: to be merged later + 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 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 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/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java new file mode 100644 index 00000000..086e8b06 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.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.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(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java new file mode 100644 index 00000000..a1f0198b --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java @@ -0,0 +1,150 @@ +/* + * 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(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java new file mode 100755 index 00000000..258598be --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.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.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(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java new file mode 100644 index 00000000..d4c3b610 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java @@ -0,0 +1,44 @@ +/* + * 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.bgp; + +import org.junit.Test; +import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP link max bandwidth attribute. + */ +public class BgpLinkAttrMaxLinkBandwidthTest { + private final float val = 0x010203; + private final short valLen = 3; + private final float val1 = 0x01020304; + private final short val1Len = 4; + + private final BgpLinkAttrMaxLinkBandwidth data = BgpLinkAttrMaxLinkBandwidth + .of(val, valLen); + private final BgpLinkAttrMaxLinkBandwidth sameAsData = BgpLinkAttrMaxLinkBandwidth + .of(val, valLen); + private final BgpLinkAttrMaxLinkBandwidth diffData = BgpLinkAttrMaxLinkBandwidth + .of(val1, val1Len); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java new file mode 100644 index 00000000..7ba6a880 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java @@ -0,0 +1,42 @@ +/* + * 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.bgp; + +import org.junit.Test; +import org.onosproject.bgpio.types.attr.BgpPrefixAttrOpaqueData; + +import com.google.common.testing.EqualsTester; + +/** + * Test for prefix attribute opaque data Tlv. + */ +public class BgpPrefixAttrOpaqueDataTest { + private final byte[] array = new byte[] {0x01, 0x02, 0x03, 0x04}; + private final byte[] array1 = new byte[] {0x01, 0x02, 0x03, 0x01}; + + private final BgpPrefixAttrOpaqueData isisData = BgpPrefixAttrOpaqueData + .of(array); + private final BgpPrefixAttrOpaqueData sameAsIsisData = BgpPrefixAttrOpaqueData + .of(array); + private final BgpPrefixAttrOpaqueData isisDiff = BgpPrefixAttrOpaqueData + .of(array1); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(isisData, sameAsIsisData) + .addEqualityGroup(isisDiff).testEquals(); + } +} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java new file mode 100644 index 00000000..02a06e05 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java @@ -0,0 +1,40 @@ +/* + * 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; + +import org.junit.Test; +import org.onosproject.bgpio.types.LocalPref; + +import com.google.common.testing.EqualsTester; + +/** + * Test for LocalPref BGP Path Attribute. + */ +public class LocalPrefTest { + private final int value1 = 800; + private final int value2 = 300; + private final LocalPref attr1 = new LocalPref(value1); + private final LocalPref sameAsAttr1 = new LocalPref(value1); + private final LocalPref attr2 = new LocalPref(value2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java new file mode 100644 index 00000000..eafcec74 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java @@ -0,0 +1,40 @@ +/* + * 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; + +import org.junit.Test; +import org.onosproject.bgpio.types.Med; + +import com.google.common.testing.EqualsTester; + +/** + * Test for MED BGP Path Attribute. + */ +public class MedTest { + private final int value1 = 800; + private final int value2 = 200; + private final Med attr1 = new Med(value1); + private final Med sameAsAttr1 = new Med(value1); + private final Med attr2 = new Med(value2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .testEquals(); + } +} -- cgit 1.2.3-korg