Search in sources :

Example 1 with IsIsPseudonode

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

the class BgpDpid method add.

/**
 * Obtains instance of this class by appending stringBuilder with node descriptor value.
 *
 * @param value node descriptor
 * @return instance of this class
 */
public BgpDpid add(final NodeDescriptors value) {
    log.debug("BgpDpid :: add function");
    if (value != null) {
        List<BgpValueType> subTlvs = value.getSubTlvs();
        ListIterator<BgpValueType> listIterator = subTlvs.listIterator();
        while (listIterator.hasNext()) {
            BgpValueType tlv = listIterator.next();
            if (tlv.getType() == AutonomousSystemTlv.TYPE) {
                this.stringBuilder.append(":ASN=").append(((AutonomousSystemTlv) tlv).getAsNum());
            } else if (tlv.getType() == BgpLSIdentifierTlv.TYPE) {
                this.stringBuilder.append(":DOMAINID=").append(((BgpLSIdentifierTlv) tlv).getBgpLsIdentifier());
            } else if (tlv.getType() == NodeDescriptors.IGP_ROUTERID_TYPE) {
                if (tlv instanceof IsIsNonPseudonode) {
                    this.stringBuilder.append(":ISOID=").append(isoNodeIdString(((IsIsNonPseudonode) tlv).getIsoNodeId()));
                } else if (tlv instanceof IsIsPseudonode) {
                    IsIsPseudonode isisPseudonode = ((IsIsPseudonode) tlv);
                    this.stringBuilder.append(":ISOID=").append(isoNodeIdString(((IsIsPseudonode) tlv).getIsoNodeId()));
                    this.stringBuilder.append(":PSN=").append(isisPseudonode.getPsnIdentifier());
                } else if (tlv instanceof OspfNonPseudonode) {
                    this.stringBuilder.append(":RID=").append(((OspfNonPseudonode) tlv).getrouterID());
                } else if (tlv instanceof OspfPseudonode) {
                    this.stringBuilder.append(":RID=").append(((OspfPseudonode) tlv).getrouterID());
                }
            }
        }
    }
    return this;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) IsIsPseudonode(org.onosproject.bgpio.types.IsIsPseudonode) OspfPseudonode(org.onosproject.bgpio.types.OspfPseudonode) BgpLSIdentifierTlv(org.onosproject.bgpio.types.BgpLSIdentifierTlv) OspfNonPseudonode(org.onosproject.bgpio.types.OspfNonPseudonode) IsIsNonPseudonode(org.onosproject.bgpio.types.IsIsNonPseudonode)

Example 2 with IsIsPseudonode

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

the class BgpUpdateMsgTest method bgpUpdateMessageTest20.

/**
 * This test case checks update message with link NLRI.
 */
@Test
public void bgpUpdateMessageTest20() 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) 0x83, 0x02, 0x00, 0x04, // withdrawn routes
    0x18, // withdrawn routes
    0x0a, // withdrawn routes
    0x01, // withdrawn routes
    0x01, // path attribute len
    0x00, // path attribute len
    0x68, // 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 };
    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;
    assertThat(other.getHeader().getMarker(), is(MARKER));
    assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE));
    assertThat(other.getHeader().getLength(), is((short) 131));
    ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
    byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
    IpPrefix testPrefixValue = listIterator1.next();
    assertThat(testPrefixValue.prefixLength(), is((int) 24));
    assertThat(testPrefixValue.address().toOctets(), is(prefix));
    BgpValueType testPathAttribute;
    Origin origin;
    AsPath asPath;
    Med med;
    MpReachNlri mpReach;
    List<BgpValueType> pathAttributes = new LinkedList<>();
    BgpPathAttributes actualpathAttribute = other.bgpPathAttributes();
    pathAttributes = actualpathAttribute.pathAttributes();
    ListIterator<BgpValueType> listIterator = pathAttributes.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));
    BgpLinkLsNlriVer4 testlinknlri = (BgpLinkLsNlriVer4) testnlri;
    NodeDescriptors testLocalNodeDescriptors = testlinknlri.localNodeDescriptors();
    List<BgpValueType> testSubTlvs = new LinkedList<>();
    testSubTlvs = testLocalNodeDescriptors.getSubTlvs();
    ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator();
    AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next();
    assertThat(testAutonomousSystemTlv.getAsNum(), is(2222));
    assertThat(testAutonomousSystemTlv.getType(), is((short) 512));
    BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next();
    assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018));
    assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513));
    IsIsPseudonode testIsIsPseudonode = (IsIsPseudonode) subtlvlist1.next();
    assertThat(testIsIsPseudonode.getPsnIdentifier(), is((byte) 3));
    assertThat(testIsIsPseudonode.getType(), is((short) 515));
    NodeDescriptors testRemoteNodeDescriptors = testlinknlri.remoteNodeDescriptors();
    testSubTlvs = testRemoteNodeDescriptors.getSubTlvs();
    ListIterator<BgpValueType> subtlvlist2 = testSubTlvs.listIterator();
    testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist2.next();
    assertThat(testAutonomousSystemTlv.getAsNum(), is(2222));
    assertThat(testAutonomousSystemTlv.getType(), is((short) 512));
    testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist2.next();
    assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018));
    assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513));
    IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist2.next();
    byte[] expIsoNodeId = new byte[] { 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21 };
    assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId));
    assertThat(testIsIsNonPseudonode.getType(), is((short) 515));
}
Also used : Origin(org.onosproject.bgpio.types.Origin) IsIsPseudonode(org.onosproject.bgpio.types.IsIsPseudonode) BgpHeader(org.onosproject.bgpio.types.BgpHeader) NodeDescriptors(org.onosproject.bgpio.protocol.linkstate.NodeDescriptors) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) IpPrefix(org.onlab.packet.IpPrefix) BgpValueType(org.onosproject.bgpio.types.BgpValueType) OriginType(org.onosproject.bgpio.types.Origin.OriginType) BgpLSIdentifierTlv(org.onosproject.bgpio.types.BgpLSIdentifierTlv) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) BgpLinkLsNlriVer4(org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4) IsIsNonPseudonode(org.onosproject.bgpio.types.IsIsNonPseudonode) AsPath(org.onosproject.bgpio.types.AsPath) BgpPathAttributes(org.onosproject.bgpio.protocol.ver4.BgpPathAttributes) AutonomousSystemTlv(org.onosproject.bgpio.types.AutonomousSystemTlv) ProtocolType(org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri) Test(org.junit.Test)

Example 3 with IsIsPseudonode

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

the class NodeDescriptors method compareTo.

/**
 * Compares this and o object.
 *
 * @param o object to be compared with this object
 * @return which object is greater
 */
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }
    ListIterator<BgpValueType> listIterator = subTlvs.listIterator();
    int countOtherSubTlv = ((NodeDescriptors) o).subTlvs.size();
    int countObjSubTlv = subTlvs.size();
    boolean tlvFound = false;
    if (countOtherSubTlv != countObjSubTlv) {
        if (countOtherSubTlv > countObjSubTlv) {
            return 1;
        } else {
            return -1;
        }
    } else {
        while (listIterator.hasNext()) {
            BgpValueType tlv1 = listIterator.next();
            log.debug("NodeDescriptor compare subtlv's");
            for (BgpValueType tlv : ((NodeDescriptors) o).subTlvs) {
                if (tlv.getType() == tlv1.getType()) {
                    if (tlv.getType() == IGP_ROUTERID_TYPE) {
                        if ((tlv1 instanceof IsIsNonPseudonode && tlv instanceof IsIsPseudonode) || (tlv1 instanceof IsIsPseudonode && tlv instanceof IsIsNonPseudonode) || (tlv1 instanceof OspfNonPseudonode && tlv instanceof OspfPseudonode) || (tlv1 instanceof OspfPseudonode && tlv instanceof OspfNonPseudonode)) {
                            continue;
                        }
                    }
                    int result = subTlvs.get(subTlvs.indexOf(tlv1)).compareTo(((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv)));
                    if (result != 0) {
                        return result;
                    }
                    tlvFound = true;
                    break;
                }
            }
            if (!tlvFound) {
                return 1;
            }
        }
    }
    return 0;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) IsIsPseudonode(org.onosproject.bgpio.types.IsIsPseudonode) OspfPseudonode(org.onosproject.bgpio.types.OspfPseudonode) OspfNonPseudonode(org.onosproject.bgpio.types.OspfNonPseudonode) IsIsNonPseudonode(org.onosproject.bgpio.types.IsIsNonPseudonode)

Aggregations

BgpValueType (org.onosproject.bgpio.types.BgpValueType)3 IsIsNonPseudonode (org.onosproject.bgpio.types.IsIsNonPseudonode)3 IsIsPseudonode (org.onosproject.bgpio.types.IsIsPseudonode)3 BgpLSIdentifierTlv (org.onosproject.bgpio.types.BgpLSIdentifierTlv)2 OspfNonPseudonode (org.onosproject.bgpio.types.OspfNonPseudonode)2 OspfPseudonode (org.onosproject.bgpio.types.OspfPseudonode)2 LinkedList (java.util.LinkedList)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 Test (org.junit.Test)1 IpPrefix (org.onlab.packet.IpPrefix)1 BgpLinkLsNlriVer4 (org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4)1 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)1 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)1 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)1 AsPath (org.onosproject.bgpio.types.AsPath)1 AutonomousSystemTlv (org.onosproject.bgpio.types.AutonomousSystemTlv)1 BgpHeader (org.onosproject.bgpio.types.BgpHeader)1 Med (org.onosproject.bgpio.types.Med)1 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)1 Origin (org.onosproject.bgpio.types.Origin)1