Search in sources :

Example 1 with MpReachNlri

use of org.onosproject.bgpio.types.MpReachNlri in project onos by opennetworkinglab.

the class BgpPathAttributes method write.

/**
 * Write path attributes to channelBuffer.
 *
 * @param cb channelBuffer
 * @return object of BgpPathAttributes
 * @throws BgpParseException while parsing BGP path attributes
 */
public int write(ChannelBuffer cb) throws BgpParseException {
    if (pathAttribute == null) {
        return 0;
    }
    int iLenStartIndex = cb.writerIndex();
    ListIterator<BgpValueType> iterator = pathAttribute.listIterator();
    int pathAttributeIndx = cb.writerIndex();
    cb.writeShort(0);
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        switch(attr.getType()) {
            case Origin.ORIGIN_TYPE:
                Origin origin = (Origin) attr;
                origin.write(cb);
                break;
            case AsPath.ASPATH_TYPE:
                AsPath asPath = (AsPath) attr;
                asPath.write(cb);
                break;
            case As4Path.AS4PATH_TYPE:
                As4Path as4Path = (As4Path) attr;
                as4Path.write(cb);
                break;
            case NextHop.NEXTHOP_TYPE:
                NextHop nextHop = (NextHop) attr;
                nextHop.write(cb);
                break;
            case Med.MED_TYPE:
                Med med = (Med) attr;
                med.write(cb);
                break;
            case LocalPref.LOCAL_PREF_TYPE:
                LocalPref localPref = (LocalPref) attr;
                localPref.write(cb);
                break;
            case Constants.BGP_EXTENDED_COMMUNITY:
                BgpExtendedCommunity extendedCommunity = (BgpExtendedCommunity) attr;
                extendedCommunity.write(cb);
                break;
            case WideCommunity.TYPE:
                WideCommunity wideCommunity = (WideCommunity) attr;
                wideCommunity.write(cb);
                break;
            case MpReachNlri.MPREACHNLRI_TYPE:
                MpReachNlri mpReach = (MpReachNlri) attr;
                mpReach.write(cb);
                break;
            case MpUnReachNlri.MPUNREACHNLRI_TYPE:
                MpUnReachNlri mpUnReach = (MpUnReachNlri) attr;
                mpUnReach.write(cb);
                break;
            case LINK_STATE_ATTRIBUTE_TYPE:
                LinkStateAttributes linkState = (LinkStateAttributes) attr;
                linkState.write(cb);
                break;
            default:
                return cb.writerIndex() - iLenStartIndex;
        }
    }
    int pathAttrLen = cb.writerIndex() - pathAttributeIndx;
    cb.setShort(pathAttributeIndx, (short) (pathAttrLen - 2));
    return cb.writerIndex() - iLenStartIndex;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) MpUnReachNlri(org.onosproject.bgpio.types.MpUnReachNlri) NextHop(org.onosproject.bgpio.types.NextHop) BgpExtendedCommunity(org.onosproject.bgpio.types.BgpExtendedCommunity) Med(org.onosproject.bgpio.types.Med) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) As4Path(org.onosproject.bgpio.types.As4Path) LocalPref(org.onosproject.bgpio.types.LocalPref) WideCommunity(org.onosproject.bgpio.types.attr.WideCommunity) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri)

Example 2 with MpReachNlri

use of org.onosproject.bgpio.types.MpReachNlri in project onos by opennetworkinglab.

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test1.

/**
 * This test case checks the changes made in.
 * BgpLinkLSIdentifier
 * BgpAttrNodeMultiTopologyId
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test1() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0xe6, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xcf, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0xb3, (byte) 0x40, (byte) 0x04, (byte) 0x47, (byte) 0x10, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0xb8, (byte) 0x35, (byte) 0x2b, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x4b, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, // ---------- BgpAttrNodeMultiTopologyId for Link 1-----------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // -----------------------------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x4b, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, // ------------ BgpAttrNodeMultiTopologyId for Link 2 --------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // -----------------------------------------------------------------------------------------------------
    (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x80, (byte) 0x1d, (byte) 0x07, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x0a };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg receivedMsg = (BgpUpdateMsg) message;
    List<BgpValueType> pathAttr = receivedMsg.bgpPathAttributes().pathAttributes();
    ListIterator<BgpValueType> iterator = pathAttr.listIterator();
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        if (attr instanceof MpReachNlri) {
            List<BgpLSNlri> nlri = ((MpReachNlri) attr).mpReachNlri();
            ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
            while (listIterator.hasNext()) {
                BgpLSNlri nlriInfo = listIterator.next();
                if (nlriInfo instanceof BgpLinkLsNlriVer4) {
                    List<BgpValueType> tlvs = ((BgpLinkLsNlriVer4) nlriInfo).getLinkIdentifier().linkDescriptors();
                    for (BgpValueType tlv : tlvs) {
                        if (tlv instanceof BgpAttrNodeMultiTopologyId) {
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().size(), is(1));
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().get(0), is((short) 2));
                        }
                    }
                }
            }
        }
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpHeader(org.onosproject.bgpio.types.BgpHeader) BgpAttrNodeMultiTopologyId(org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId) BgpLinkLsNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 3 with MpReachNlri

use of org.onosproject.bgpio.types.MpReachNlri in project onos by opennetworkinglab.

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test2.

/**
 * This test case checks the changes made in.
 * BgpPrefixLSIdentifier
 * MpReachNlri (read method AFI 16388/SAFI 71 if part)
 * BgpPrefixIPv4LSNlriVer4
 * LinkStateAttributes (ATTR_PREFIX_FLAGS check)
 * BgpAttrNodeMultiTopologyId
 * Validation
 * IPReachabilityInformationTlv
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test2() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x01, (byte) 0x08, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xf1, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0xcf, (byte) 0x40, (byte) 0x04, (byte) 0x47, (byte) 0x10, // ------------ MpReachNlri Nexthop --------------------------------------------------------------------
    (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x50, // -----------------------------------------------------------------------------------------------------
    (byte) 0x54, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0xb8, (byte) 0x35, (byte) 0x2b, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x3a, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, // ------------ BgpAttrNodeMultiTopologyId for Prefix 1-------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // ------------ IPReachabilityInformationTlv for Prefix 1-----------------------------------------------
    (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x09, (byte) 0x40, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x43, (byte) 0x21, (byte) 0x00, (byte) 0x00, // -----------------------------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x3a, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, // ------------ BgpAttrNodeMultiTopologyId for Prefix 2-------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // ------------ IPReachabilityInformationTlv for Prefix 2-----------------------------------------------
    (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x09, (byte) 0x40, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x43, (byte) 0x21, (byte) 0x00, (byte) 0x00, // -----------------------------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x3a, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, // ------------ BgpAttrNodeMultiTopologyId for Prefix 3-------------------------------------------------
    (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x02, // ------------ IPReachabilityInformationTlv for Prefix 3-----------------------------------------------
    (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x09, (byte) 0x40, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, // -----------------------------------------------------------------------------------------------------
    (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x80, (byte) 0x1d, (byte) 0x0d, (byte) 0x04, (byte) 0x83, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, // ------------ BGP-LS ATTR_PREFIX_FLAGS Attribute-----------------------------------------------
    (byte) 0x04, (byte) 0x92, (byte) 0x00, (byte) 0x01, (byte) 0x00 // -----------------------------------------------------------------------------------------------------
    };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg receivedMsg = (BgpUpdateMsg) message;
    List<BgpValueType> pathAttr = receivedMsg.bgpPathAttributes().pathAttributes();
    ListIterator<BgpValueType> iterator = pathAttr.listIterator();
    short count = 0;
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        if (attr instanceof MpReachNlri) {
            List<BgpLSNlri> nlri = ((MpReachNlri) attr).mpReachNlri();
            assertThat(((MpReachNlri) attr).nexthop().toString(), is("2001:5b0:8:0:5054:ff:feb8:352b"));
            ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
            while (listIterator.hasNext()) {
                BgpLSNlri nlriInfo = listIterator.next();
                assertThat(nlriInfo, instanceOf(BgpPrefixIPv4LSNlriVer4.class));
                if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) {
                    List<BgpValueType> tlvs = ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getPrefixIdentifier().getPrefixdescriptor();
                    for (BgpValueType tlv : tlvs) {
                        if (tlv instanceof BgpAttrNodeMultiTopologyId) {
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().size(), is(1));
                            assertThat(((BgpAttrNodeMultiTopologyId) tlv).attrMultiTopologyId().get(0), is((short) 2));
                        } else if (tlv instanceof IPReachabilityInformationTlv) {
                            if (count == 0) {
                                assertThat(((IPReachabilityInformationTlv) tlv).getPrefixValue().toString(), is("2001:5b0:4321::/64"));
                            } else if (count == 1) {
                                assertThat(((IPReachabilityInformationTlv) tlv).getPrefixValue().toString(), is("2001:5b0:4321::/64"));
                            } else {
                                assertThat(((IPReachabilityInformationTlv) tlv).getPrefixValue().toString(), is("2001:5b0:8::/64"));
                            }
                            count++;
                        }
                    }
                }
            }
        } else if (attr instanceof LinkStateAttributes) {
            assertThat(((LinkStateAttributes) attr).linkStateAttributes().size(), is(2));
        }
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpHeader(org.onosproject.bgpio.types.BgpHeader) BgpAttrNodeMultiTopologyId(org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId) IPReachabilityInformationTlv(org.onosproject.bgpio.types.IPReachabilityInformationTlv) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) BgpPrefixIPv4LSNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 4 with MpReachNlri

use of org.onosproject.bgpio.types.MpReachNlri in project onos by opennetworkinglab.

the class BgpUpdateLinkStateAttrTest method bgpUpdateMessageTest14.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrMplsProtocolMask.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest14() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x93, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x78, // origin
    0x04, // origin
    0x01, // origin
    0x01, // origin
    0x00, // as_path
    0x40, // as_path
    0x02, // as_path
    0x04, // as_path
    0x02, // as_path
    0x01, // as_path
    (byte) 0xfd, // as_path
    (byte) 0xe9, // med
    (byte) 0x80, // med
    0x04, // med
    0x04, // med
    0x00, // med
    0x00, // med
    0x00, // med
    0x00, // mpreach
    (byte) 0x80, // mpreach
    0x0e, // mpreach
    0x53, // mpreach
    0x40, // mpreach
    0x04, // mpreach
    0x47, // nexthop
    0x04, // nexthop
    0x04, // nexthop
    0x00, // nexthop
    0x00, // nexthop
    0x01, // reserved
    0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // link nlri
    0x00, // link nlri
    (byte) 0x95, // link nlri
    0x02, // link nlri
    0x50, // link nlri
    0x21, // linkstate attr
    (byte) 0x80, // linkstate attr
    0x1d, // linkstate attr
    0x0D, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x00, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    (byte) 0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, 0x04, 0x46, 0x00, 0x01, // BgpLinkAttrMplsProtocolMask
    (byte) 0xC0 };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;
    byte[] marker = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
    assertThat(other.getHeader().getMarker(), is(marker));
    assertThat(other.getHeader().getType(), is((byte) 2));
    assertThat(other.getHeader().getLength(), is((short) 147));
    ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
    byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
    while (listIterator1.hasNext()) {
        IpPrefix testPrefixValue = listIterator1.next();
        assertThat(testPrefixValue.prefixLength(), is((int) 24));
        assertThat(testPrefixValue.address().toOctets(), is(prefix));
    }
    BgpValueType testPathAttribute = null;
    Origin origin;
    AsPath aspath;
    Med med;
    MpReachNlri mpReach;
    LinkStateAttributes linkStateAttr;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    BgpPathAttributes pathAttribute = other.bgpPathAttributes();
    pathAttributeList = pathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
    OriginType originValue = OriginType.IGP;
    testPathAttribute = listIterator.next();
    origin = (Origin) testPathAttribute;
    assertThat(origin.origin(), is(originValue));
    testPathAttribute = listIterator.next();
    aspath = (AsPath) testPathAttribute;
    ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
    assertThat(listIterator2.next(), is((short) 65001));
    testPathAttribute = listIterator.next();
    med = (Med) testPathAttribute;
    assertThat(med.med(), is(0));
    testPathAttribute = listIterator.next();
    mpReach = (MpReachNlri) testPathAttribute;
    assertThat(mpReach.mpReachNlriLen(), is((int) 83));
    assertThat(mpReach.getType(), is((short) 14));
    List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
    testMpReachNlri = mpReach.mpReachNlri();
    ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
    BgpLSNlri testnlri = list1.next();
    NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
    ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
    assertThat(testnlri.getIdentifier(), is((long) 0));
    assertThat(testnlri.getNlriType(), is(nlriType));
    assertThat(testnlri.getProtocolId(), is(protocolId));
    testPathAttribute = listIterator.next();
    linkStateAttr = (LinkStateAttributes) testPathAttribute;
    assertThat(linkStateAttr.getType(), is((short) 29));
    ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
    byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
    Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
    assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
    BgpLinkAttrMplsProtocolMask obj = new BgpLinkAttrMplsProtocolMask(true, true);
    assertThat(((BgpLinkAttrMplsProtocolMask) list.next()).equals(obj), is(true));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) BgpLinkAttrMplsProtocolMask(org.onosproject.bgpio.types.attr.BgpLinkAttrMplsProtocolMask) Ip4Address(org.onlab.packet.Ip4Address) BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) BgpValueType(org.onosproject.bgpio.types.BgpValueType) OriginType(org.onosproject.bgpio.types.Origin.OriginType) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 5 with MpReachNlri

use of org.onosproject.bgpio.types.MpReachNlri in project onos by opennetworkinglab.

the class BgpUpdateLinkStateAttrTest method bgpUpdateMessageTest16.

/**
 * Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrOpaqLnkAttrib.
 *
 * @throws BgpParseException while parsing update message
 */
@Test
public void bgpUpdateMessageTest16() throws BgpParseException {
    byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A, // withdrawn routes
    0x02, // withdrawn routes
    0x00, // withdrawn routes
    0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // origin
    0x00, // origin
    0x7F, // origin
    0x04, // origin
    0x01, // origin
    0x01, // origin
    0x00, // as_path
    0x40, // as_path
    0x02, // as_path
    0x04, // as_path
    0x02, // as_path
    0x01, // as_path
    (byte) 0xfd, // as_path
    (byte) 0xe9, // mpreach
    (byte) 0x80, // mpreach
    0x04, // mpreach
    0x04, // mpreach
    0x00, // mpreach
    0x00, // mpreach
    0x00, // mpreach
    0x00, // mpreach
    (byte) 0x80, // mpreach
    0x0e, // mpreach
    0x53, // mpreach
    0x40, // mpreach
    0x04, // mpreach
    0x47, 0x04, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, // linkstate attr
    0x00, // linkstate attr
    (byte) 0x95, // linkstate attr
    0x02, // linkstate attr
    0x50, // linkstate attr
    0x21, // linkstate attr
    (byte) 0x80, // linkstate attr
    0x1d, // linkstate attr
    0x14, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    0x00, // BgpAttrRouterIdV4
    0x04, // BgpAttrRouterIdV4
    (byte) 0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, // BgpAttrRouterIdV4
    0x15, 0x04, 0x49, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, // BgpLinkAttrOpaqLnkAttrib
    0x0b };
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);
    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message = null;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);
    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;
    byte[] marker = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
    assertThat(other.getHeader().getMarker(), is(marker));
    assertThat(other.getHeader().getType(), is((byte) 2));
    assertThat(other.getHeader().getLength(), is((short) 154));
    BgpValueType testPathAttribute = null;
    Origin origin;
    AsPath aspath;
    Med med;
    MpReachNlri mpReach;
    LinkStateAttributes linkStateAttr;
    List<BgpValueType> pathAttributeList = new LinkedList<>();
    BgpPathAttributes pathAttribute = other.bgpPathAttributes();
    pathAttributeList = pathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
    OriginType originValue = OriginType.IGP;
    testPathAttribute = listIterator.next();
    origin = (Origin) testPathAttribute;
    assertThat(origin.origin(), is(originValue));
    testPathAttribute = listIterator.next();
    aspath = (AsPath) testPathAttribute;
    ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
    assertThat(listIterator2.next(), is((short) 65001));
    testPathAttribute = listIterator.next();
    med = (Med) testPathAttribute;
    assertThat(med.med(), is(0));
    testPathAttribute = listIterator.next();
    mpReach = (MpReachNlri) testPathAttribute;
    assertThat(mpReach.mpReachNlriLen(), is((int) 83));
    assertThat(mpReach.getType(), is((short) 14));
    List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
    testMpReachNlri = mpReach.mpReachNlri();
    ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
    BgpLSNlri testnlri = list1.next();
    ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
    assertThat(testnlri.getProtocolId(), is(protocolId));
    testPathAttribute = listIterator.next();
    linkStateAttr = (LinkStateAttributes) testPathAttribute;
    assertThat(linkStateAttr.getType(), is((short) 29));
    ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
    byte[] ipBytes = new byte[] { (byte) 0x15, 0x15, 0x15, 0x15 };
    Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
    assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
    byte[] attrOpaqLnkAttrib = new byte[] { 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b };
    assertThat(((BgpLinkAttrOpaqLnkAttrib) list.next()).attrOpaqueLnk(), is(attrOpaqLnkAttrib));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) OriginType(org.onosproject.bgpio.types.Origin.OriginType) Ip4Address(org.onlab.packet.Ip4Address) BgpHeader(org.onosproject.bgpio.types.BgpHeader) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Aggregations

BgpValueType (org.onosproject.bgpio.types.BgpValueType)31 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)31 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)26 Test (org.junit.Test)26 AsPath (org.onosproject.bgpio.types.AsPath)26 BgpHeader (org.onosproject.bgpio.types.BgpHeader)26 Origin (org.onosproject.bgpio.types.Origin)26 LinkedList (java.util.LinkedList)25 Med (org.onosproject.bgpio.types.Med)25 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)23 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)23 OriginType (org.onosproject.bgpio.types.Origin.OriginType)23 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)22 IpPrefix (org.onlab.packet.IpPrefix)18 Ip4Address (org.onlab.packet.Ip4Address)12 MpUnReachNlri (org.onosproject.bgpio.types.MpUnReachNlri)5 ArrayList (java.util.ArrayList)3 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)3 As4Path (org.onosproject.bgpio.types.As4Path)3 AutonomousSystemTlv (org.onosproject.bgpio.types.AutonomousSystemTlv)3