Search in sources :

Example 1 with WideCommunityIpV4Neighbour

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

the class WideCommunity method decodeWideCommunityTlv.

/**
 * Decode wide community target(s).
 *
 * @param c channel buffer
 * @return target list
 * @throws BgpParseException on decode error
 */
public static List<BgpValueType> decodeWideCommunityTlv(ChannelBuffer c) throws BgpParseException {
    List<BgpValueType> targetTlv = new ArrayList<>();
    while (c.readableBytes() > 0) {
        if (c.readableBytes() < TYPE_LENGTH_SIZE) {
            Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, c.readableBytes());
        }
        byte atomType = c.readByte();
        short atomLength = c.readShort();
        if (c.readableBytes() < atomLength) {
            Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, atomLength);
        }
        if (atomType == WideCommunityIpV4Neighbour.TYPE) {
            ChannelBuffer tempBuf = c.readBytes(atomLength);
            WideCommunityIpV4Neighbour wideCommAtom = new WideCommunityIpV4Neighbour();
            while (tempBuf.readableBytes() > 0) {
                wideCommAtom.add(IpAddress.valueOf(tempBuf.readInt()), IpAddress.valueOf(tempBuf.readInt()));
            }
            targetTlv.add(wideCommAtom);
        } else if (atomType == WideCommunityInteger.TYPE) {
            ChannelBuffer tempBuf = c.readBytes(atomLength);
            List<Integer> integer = new ArrayList<>();
            while (tempBuf.readableBytes() > 0) {
                integer.add(tempBuf.readInt());
            }
            targetTlv.add(new WideCommunityInteger(integer));
        } else {
            Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, atomLength);
        }
    }
    return targetTlv;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) WideCommunityInteger(org.onosproject.bgpio.types.WideCommunityInteger) ArrayList(java.util.ArrayList) WideCommunityIpV4Neighbour(org.onosproject.bgpio.types.WideCommunityIpV4Neighbour) ArrayList(java.util.ArrayList) List(java.util.List) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 2 with WideCommunityIpV4Neighbour

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

the class WideCommunity method encodeWideCommunityTlv.

/**
 * Encode wide community target(s).
 *
 * @param c channel buffer
 * @param targetTlv wide community include/exclude target
 */
public static void encodeWideCommunityTlv(ChannelBuffer c, List<BgpValueType> targetTlv) {
    /*
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         |  IPV4Neig(8)  |   Length:                   8 |
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         | local                                               10101010  |
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         | remote                                              10101010  |
         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         * */
    List<BgpValueType> target = targetTlv;
    if (target == null) {
        log.debug("target is null");
        return;
    }
    Iterator<BgpValueType> listIterator = targetTlv.iterator();
    while (listIterator.hasNext()) {
        BgpValueType attr = listIterator.next();
        if (attr instanceof WideCommunityIpV4Neighbour) {
            WideCommunityIpV4Neighbour ipv4Neig = (WideCommunityIpV4Neighbour) attr;
            ipv4Neig.write(c);
        } else if (attr instanceof WideCommunityInteger) {
            WideCommunityInteger integer = (WideCommunityInteger) attr;
            integer.write(c);
        }
    }
    return;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) WideCommunityInteger(org.onosproject.bgpio.types.WideCommunityInteger) WideCommunityIpV4Neighbour(org.onosproject.bgpio.types.WideCommunityIpV4Neighbour)

Aggregations

BgpValueType (org.onosproject.bgpio.types.BgpValueType)2 WideCommunityInteger (org.onosproject.bgpio.types.WideCommunityInteger)2 WideCommunityIpV4Neighbour (org.onosproject.bgpio.types.WideCommunityIpV4Neighbour)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1