Search in sources :

Example 6 with MpUnReachNlri

use of org.onosproject.bgpio.types.MpUnReachNlri 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 7 with MpUnReachNlri

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

the class BgpUpdateMsg2Test method bgpUpdateMessage2Test6.

/**
 * This test case checks the changes made in.
 * MpUnReachNlri (read method AFI 2/SAFI 1 else if part)
 * as bug fix for bug 8036
 */
@Test
public void bgpUpdateMessage2Test6() 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) 0x1d, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x80, (byte) 0x0f, (byte) 0x03, // ------------ AFI = 2 --------------------------------------------------------------------------------
    (byte) 0x00, (byte) 0x02, // ------------ SAFI = 1 -------------------------------------------------------------------------------
    (byte) 0x01 // -----------------------------------------------------------------------------------------------------
    };
    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 MpUnReachNlri) {
            assertThat(((MpUnReachNlri) attr).getAfi(), is((short) 2));
            assertThat(((MpUnReachNlri) attr).getSafi(), is((byte) 1));
        }
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) MpUnReachNlri(org.onosproject.bgpio.types.MpUnReachNlri) BgpHeader(org.onosproject.bgpio.types.BgpHeader) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Aggregations

BgpValueType (org.onosproject.bgpio.types.BgpValueType)7 MpUnReachNlri (org.onosproject.bgpio.types.MpUnReachNlri)7 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)5 AsPath (org.onosproject.bgpio.types.AsPath)4 Origin (org.onosproject.bgpio.types.Origin)4 LinkedList (java.util.LinkedList)3 As4Path (org.onosproject.bgpio.types.As4Path)3 BgpExtendedCommunity (org.onosproject.bgpio.types.BgpExtendedCommunity)3 Med (org.onosproject.bgpio.types.Med)3 ArrayList (java.util.ArrayList)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 Test (org.junit.Test)2 BgpMessage (org.onosproject.bgpio.protocol.BgpMessage)2 BgpHeader (org.onosproject.bgpio.types.BgpHeader)2 LocalPref (org.onosproject.bgpio.types.LocalPref)2 IpPrefix (org.onlab.packet.IpPrefix)1 BgpPeer (org.onosproject.bgp.controller.BgpPeer)1 BgpRouteListener (org.onosproject.bgp.controller.BgpRouteListener)1 BgpLSNlri (org.onosproject.bgpio.protocol.BgpLSNlri)1 BgpUpdateMsg (org.onosproject.bgpio.protocol.BgpUpdateMsg)1