Search in sources :

Example 1 with Validation

use of org.onosproject.bgpio.util.Validation in project onos by opennetworkinglab.

the class As4Path method read.

/**
 * 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);
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) ArrayList(java.util.ArrayList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 2 with Validation

use of org.onosproject.bgpio.util.Validation in project onos by opennetworkinglab.

the class BgpExtendedCommunity method read.

/**
 * Reads from the channel buffer and parses extended community.
 *
 * @param cb ChannelBuffer
 * @return object of BgpExtendedCommunity
 * @throws BgpParseException while parsing extended community
 */
public static BgpExtendedCommunity read(ChannelBuffer cb) throws BgpParseException {
    ChannelBuffer tempCb = cb.copy();
    Validation validation = Validation.parseAttributeHeader(cb);
    List<BgpValueType> fsActionTlvs = new LinkedList<>();
    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());
    if (tempBuf.readableBytes() > 0) {
        BgpValueType fsActionTlv = null;
        ChannelBuffer actionBuf = tempBuf.readBytes(validation.getLength());
        while (actionBuf.readableBytes() > 0) {
            short actionType = actionBuf.readShort();
            switch(actionType) {
                case Constants.BGP_ROUTE_TARGET_AS:
                case Constants.BGP_ROUTE_TARGET_IP:
                case Constants.BGP_ROUTE_TARGET_LARGEAS:
                    fsActionTlv = RouteTarget.read(actionType, actionBuf);
                    break;
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION:
                    fsActionTlv = BgpFsActionTrafficAction.read(actionBuf);
                    break;
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING:
                    fsActionTlv = BgpFsActionTrafficMarking.read(actionBuf);
                    break;
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_RATE:
                    fsActionTlv = BgpFsActionTrafficRate.read(actionBuf);
                    break;
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT:
                    fsActionTlv = BgpFsActionReDirect.read(actionBuf);
                    break;
                default:
                    log.debug("Other type Not Supported:" + actionType);
                    break;
            }
            if (fsActionTlv != null) {
                fsActionTlvs.add(fsActionTlv);
            }
        }
    }
    return new BgpExtendedCommunity(fsActionTlvs);
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 3 with Validation

use of org.onosproject.bgpio.util.Validation in project onos by opennetworkinglab.

the class LinkStateAttributes method read.

/**
 * 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.copy();
    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*/
                int tlvLength = tempCb.readShort();
                bgpLSAttrib = BgpAttrNodeMultiTopologyId.read(tempCb, tlvLength);
                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;
            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 */
                // 2
                bgpLSAttrib = BgpLinkAttrMplsProtocolMask.read(tempCb);
                break;
            case ATTR_LINK_IGP_METRIC:
                /* IGP Metric */
                // 2
                bgpLSAttrib = BgpLinkAttrIgpMetric.read(tempCb);
                break;
            case ATTR_LINK_SHR_RISK_GRP:
                /* Shared Risk Link Group */
                // 3
                bgpLSAttrib = BgpLinkAttrSrlg.read(tempCb);
                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;
            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;
            case ATTR_PREFIX_FLAGS:
            case ATTR_EXTENDED_ADMINISTRATIVE_GROUP:
                // We are not using these bytes, but simply skipping them.
                // If we don't skip but simply ignore these, the while loop
                // reads wrong bytes and throws BgpParseException
                // TODO : Use these bytes if required
                int prefixFlagsLength = tempCb.readShort();
                if (tempCb.readableBytes() > 0) {
                    tempCb.skipBytes(prefixFlagsLength);
                }
                break;
            default:
                throw new BgpParseException("The Bgp-LS Attribute is not supported : " + tlvCodePoint);
        }
        linkStateAttribList.add(bgpLSAttrib);
    }
    return new LinkStateAttributes(linkStateAttribList);
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 4 with Validation

use of org.onosproject.bgpio.util.Validation in project onos by opennetworkinglab.

the class Med method read.

/**
 * 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);
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 5 with Validation

use of org.onosproject.bgpio.util.Validation in project onos by opennetworkinglab.

the class MpReachNlri method read.

/**
 * 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;
    IpAddress 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 = IpAddress.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:
                    case BgpPrefixIPv4LSNlriVer4.PREFIX_IPV6_NLRITYPE:
                        // RFC 7752 : Structure of IPv4 and IPv6 is same
                        bgpLSNlri = BgpPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi);
                        break;
                    default:
                        log.debug("nlriType not supported" + nlriType);
                }
                mpReachNlri.add(bgpLSNlri);
            }
        } else if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
            List<BgpValueType> flowSpecComponents = new LinkedList<>();
            RouteDistinguisher routeDistinguisher = null;
            if (tempCb.readableBytes() > 0) {
                BgpValueType flowSpecComponent = null;
                byte nextHopLen = tempCb.readByte();
                if (nextHopLen > 0) {
                    InetAddress ipAddress = Validation.toInetAddress(nextHopLen, tempCb);
                    if (ipAddress.isMulticastAddress()) {
                        throw new BgpParseException("Multicast not supported");
                    }
                    ipNextHop = IpAddress.valueOf(ipAddress);
                }
                byte reserved = tempCb.readByte();
                if (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE) {
                    routeDistinguisher = new RouteDistinguisher();
                    routeDistinguisher = RouteDistinguisher.read(tempCb);
                }
                while (tempCb.readableBytes() > 0) {
                    short totNlriLen = tempCb.getUnsignedByte(tempCb.readerIndex());
                    if (totNlriLen >= BgpFlowSpecNlri.FLOW_SPEC_LEN) {
                        if (tempCb.readableBytes() < 2) {
                            Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
                        }
                        totNlriLen = tempCb.readShort();
                    } else {
                        totNlriLen = tempCb.readByte();
                    }
                    if (tempCb.readableBytes() < totNlriLen) {
                        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen);
                    }
                    tempBuf = tempCb.readBytes(totNlriLen);
                    while (tempBuf.readableBytes() > 0) {
                        short type = tempBuf.readByte();
                        switch(type) {
                            case Constants.BGP_FLOWSPEC_DST_PREFIX:
                                flowSpecComponent = BgpFsDestinationPrefix.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_SRC_PREFIX:
                                flowSpecComponent = BgpFsSourcePrefix.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_IP_PROTO:
                                flowSpecComponent = BgpFsIpProtocol.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_PORT:
                                flowSpecComponent = BgpFsPortNum.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_DST_PORT:
                                flowSpecComponent = BgpFsDestinationPortNum.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_SRC_PORT:
                                flowSpecComponent = BgpFsSourcePortNum.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_ICMP_TP:
                                flowSpecComponent = BgpFsIcmpType.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_ICMP_CD:
                                flowSpecComponent = BgpFsIcmpCode.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_TCP_FLAGS:
                                flowSpecComponent = BgpFsTcpFlags.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_PCK_LEN:
                                flowSpecComponent = BgpFsPacketLength.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_DSCP:
                                flowSpecComponent = BgpFsDscpValue.read(tempBuf);
                                break;
                            case Constants.BGP_FLOWSPEC_FRAGMENT:
                                flowSpecComponent = BgpFsFragment.read(tempBuf);
                                break;
                            default:
                                log.debug("flow spec type not supported" + type);
                                break;
                        }
                        flowSpecComponents.add(flowSpecComponent);
                    }
                }
            }
            BgpFlowSpecNlri flowSpecDetails = new BgpFlowSpecNlri(flowSpecComponents);
            flowSpecDetails.setRouteDistinguiher(routeDistinguisher);
            return new MpReachNlri(flowSpecDetails, afi, safi);
        } else if ((afi == Constants.AFI_EVPN_VALUE) && (safi == Constants.SAFI_EVPN_VALUE)) {
            List<BgpEvpnNlri> eVpnComponents = null;
            byte nextHopLen = tempCb.readByte();
            InetAddress ipAddress = Validation.toInetAddress(nextHopLen, tempCb);
            if (ipAddress.isMulticastAddress()) {
                throw new BgpParseException("Multicast not supported");
            }
            ipNextHop = IpAddress.valueOf(ipAddress);
            byte reserved = tempCb.readByte();
            while (tempCb.readableBytes() > 0) {
                BgpEvpnNlri eVpnComponent = BgpEvpnNlriImpl.read(tempCb);
                eVpnComponents = new LinkedList<>();
                eVpnComponents.add(eVpnComponent);
                log.info("=====evpn Component is {} ======", eVpnComponent);
            }
            return new MpReachNlri(eVpnComponents, afi, safi, ipNextHop);
        } else if ((afi == Constants.AFI_IPV4_UNICAST && safi == Constants.SAFI_UNICAST) || (afi == Constants.AFI_IPV6_UNICAST && safi == Constants.SAFI_UNICAST)) {
            byte nextHopLen = tempCb.readByte();
            InetAddress ipAddress = Validation.toInetAddress(nextHopLen, tempCb);
            if (ipAddress.isMulticastAddress()) {
                throw new BgpParseException("Multicast not supported");
            }
            ipNextHop = IpAddress.valueOf(ipAddress);
            byte snpa = tempCb.readByte();
            // TODO : Use this info, if required
            if (tempCb.readableBytes() > 0) {
                // Convert bits to bytes
                int mpReachNlriPrefixLength = tempCb.readByte() / ONE_BYTE_LENGTH;
                tempCb.skipBytes(mpReachNlriPrefixLength);
            }
            return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength());
        } else {
            throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi);
        }
    }
    return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength());
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) BgpFlowSpecNlri(org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) BgpLSNlri(org.onosproject.bgpio.protocol.BgpLSNlri) IpAddress(org.onlab.packet.IpAddress) List(java.util.List) LinkedList(java.util.LinkedList) BgpEvpnNlri(org.onosproject.bgpio.protocol.BgpEvpnNlri) InetAddress(java.net.InetAddress)

Aggregations

ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)10 BgpParseException (org.onosproject.bgpio.exceptions.BgpParseException)10 Validation (org.onosproject.bgpio.util.Validation)10 LinkedList (java.util.LinkedList)3 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BgpEvpnNlri (org.onosproject.bgpio.protocol.BgpEvpnNlri)2 BgpLSNlri (org.onosproject.bgpio.protocol.BgpLSNlri)2 BgpFlowSpecNlri (org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri)2 Ip4Address (org.onlab.packet.Ip4Address)1 IpAddress (org.onlab.packet.IpAddress)1