Search in sources :

Example 51 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project bgpcep by opendaylight.

the class XROIpv6PrefixSubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
    final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
    final IpPrefix prefix = specObj.getIpPrefix();
    final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
    Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
    writeIpv6Prefix(prefix.getIpv6Prefix(), body);
    Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
    writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
    XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
Also used : IpPrefixSubobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpPrefixCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase) ByteBuf(io.netty.buffer.ByteBuf)

Example 52 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project bgpcep by opendaylight.

the class RROIpv6PrefixSubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
    final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
    final IpPrefix prefix = specObj.getIpPrefix();
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
    flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
    final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
    Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
    writeIpv6Prefix(prefix.getIpv6Prefix(), body);
    flags.toByteBuf(body);
    RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
Also used : IpPrefixSubobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpPrefixCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCase) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 53 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project bgpcep by opendaylight.

the class ReachTlvParser method serializeModel.

public static IpPrefix serializeModel(final ContainerNode prefixDesc) {
    if (prefixDesc.getChild(IP_REACH_NID).isPresent()) {
        final String prefix = (String) prefixDesc.getChild(IP_REACH_NID).get().getValue();
        try {
            final ByteBuf buffer = Unpooled.buffer(5);
            ByteBufWriteUtil.writeMinimalPrefix(new Ipv4Prefix(prefix), buffer);
            return new IpPrefix(new Ipv4Prefix(prefix));
        } catch (final IllegalArgumentException e) {
            LOG.debug("Creating Ipv6 prefix because", e);
            return new IpPrefix(new Ipv6Prefix(prefix));
        }
    }
    return null;
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) ByteBuf(io.netty.buffer.ByteBuf) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)

Example 54 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project netvirt by opendaylight.

the class Ipv6RouterAdvt method updateRAResponse.

private void updateRAResponse(Ipv6RtrAdvertType raType, RouterSolicitationPacket pdu, RouterAdvertisementPacketBuilder raPacket, VirtualPort routerPort) {
    short icmpv6RaFlags = 0;
    String gatewayMac = null;
    IpAddress gatewayIp;
    List<String> autoConfigPrefixList = new ArrayList<>();
    List<String> statefulConfigPrefixList = new ArrayList<>();
    for (VirtualSubnet subnet : routerPort.getSubnets()) {
        gatewayIp = subnet.getGatewayIp();
        // Skip if its a v4 subnet.
        if (gatewayIp.getIpv4Address() != null) {
            continue;
        }
        if (!subnet.getIpv6RAMode().isEmpty()) {
            if (Ipv6Constants.IPV6_AUTO_ADDRESS_SUBNETS.contains(subnet.getIpv6RAMode())) {
                autoConfigPrefixList.add(String.valueOf(subnet.getSubnetCidr().getValue()));
            }
            if (subnet.getIpv6RAMode().equalsIgnoreCase(Ipv6Constants.IPV6_DHCPV6_STATEFUL)) {
                statefulConfigPrefixList.add(String.valueOf(subnet.getSubnetCidr().getValue()));
            }
        }
        if (subnet.getIpv6RAMode().equalsIgnoreCase(Ipv6Constants.IPV6_DHCPV6_STATELESS)) {
            // Other Configuration.
            icmpv6RaFlags = (short) (icmpv6RaFlags | 1 << 6);
        } else if (subnet.getIpv6RAMode().equalsIgnoreCase(Ipv6Constants.IPV6_DHCPV6_STATEFUL)) {
            // Managed Address Conf.
            icmpv6RaFlags = (short) (icmpv6RaFlags | 1 << 7);
        }
    }
    gatewayMac = routerPort.getMacAddress();
    MacAddress sourceMac = MacAddress.getDefaultInstance(gatewayMac);
    raPacket.setSourceMac(sourceMac);
    if (raType == Ipv6RtrAdvertType.SOLICITED_ADVERTISEMENT) {
        raPacket.setDestinationMac(pdu.getSourceMac());
        raPacket.setDestinationIpv6(pdu.getSourceIpv6());
        raPacket.setFlowLabel(pdu.getFlowLabel());
    } else {
        raPacket.setDestinationMac(new MacAddress(Ipv6Constants.DEF_MCAST_MAC));
        raPacket.setDestinationIpv6(Ipv6ServiceUtils.ALL_NODES_MCAST_ADDR);
        raPacket.setFlowLabel(Ipv6Constants.DEF_FLOWLABEL);
    }
    raPacket.setEthertype(Ipv6Constants.IP_V6_ETHTYPE);
    raPacket.setVersion(Ipv6Constants.IPV6_VERSION);
    int prefixListLength = autoConfigPrefixList.size() + statefulConfigPrefixList.size();
    raPacket.setIpv6Length(Ipv6Constants.ICMPV6_RA_LENGTH_WO_OPTIONS + Ipv6Constants.ICMPV6_OPTION_SOURCE_LLA_LENGTH + prefixListLength * Ipv6Constants.ICMPV6_OPTION_PREFIX_LENGTH);
    raPacket.setNextHeader(Ipv6Constants.ICMP6_NHEADER);
    raPacket.setHopLimit(Ipv6Constants.ICMP_V6_MAX_HOP_LIMIT);
    raPacket.setSourceIpv6(Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(sourceMac));
    raPacket.setIcmp6Type(Ipv6Constants.ICMP_V6_RA_CODE);
    raPacket.setIcmp6Code((short) 0);
    raPacket.setIcmp6Chksum(0);
    raPacket.setCurHopLimit((short) Ipv6Constants.IPV6_DEFAULT_HOP_LIMIT);
    raPacket.setFlags(icmpv6RaFlags);
    if (raType == Ipv6RtrAdvertType.CEASE_ADVERTISEMENT) {
        raPacket.setRouterLifetime(0);
    } else {
        raPacket.setRouterLifetime(Ipv6Constants.IPV6_ROUTER_LIFETIME);
    }
    raPacket.setReachableTime((long) Ipv6Constants.IPV6_RA_REACHABLE_TIME);
    raPacket.setRetransTime((long) 0);
    raPacket.setOptionSourceAddr((short) 1);
    raPacket.setSourceAddrLength((short) 1);
    raPacket.setSourceLlAddress(MacAddress.getDefaultInstance(gatewayMac));
    List<PrefixList> prefixList = new ArrayList<>();
    PrefixListBuilder prefix = new PrefixListBuilder();
    prefix.setOptionType((short) 3);
    prefix.setOptionLength((short) 4);
    // Note: EUI-64 auto-configuration requires 64 bits.
    prefix.setPrefixLength((short) 64);
    prefix.setValidLifetime((long) Ipv6Constants.IPV6_RA_VALID_LIFETIME);
    prefix.setPreferredLifetime((long) Ipv6Constants.IPV6_RA_PREFERRED_LIFETIME);
    prefix.setReserved((long) 0);
    short autoConfPrefixFlags = 0;
    // On-link flag
    autoConfPrefixFlags = (short) (autoConfPrefixFlags | 1 << 7);
    // Autonomous address-configuration flag.
    autoConfPrefixFlags = (short) (autoConfPrefixFlags | 1 << 6);
    for (String v6Prefix : autoConfigPrefixList) {
        prefix.setFlags(autoConfPrefixFlags);
        prefix.setPrefix(new Ipv6Prefix(v6Prefix));
        prefixList.add(prefix.build());
    }
    short statefulPrefixFlags = 0;
    // On-link flag
    statefulPrefixFlags = (short) (statefulPrefixFlags | 1 << 7);
    for (String v6Prefix : statefulConfigPrefixList) {
        prefix.setFlags(statefulPrefixFlags);
        prefix.setPrefix(new Ipv6Prefix(v6Prefix));
        prefixList.add(prefix.build());
    }
    raPacket.setPrefixList(prefixList);
    return;
}
Also used : ArrayList(java.util.ArrayList) PrefixListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.router.advertisement.packet.PrefixListBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PrefixList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.router.advertisement.packet.PrefixList) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)

Example 55 with Ipv6Prefix

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix in project netvirt by opendaylight.

the class Ipv6RouterAdvt method icmp6RAPayloadtoByte.

private byte[] icmp6RAPayloadtoByte(RouterAdvertisementPacket pdu) {
    byte[] data = new byte[pdu.getIpv6Length()];
    Arrays.fill(data, (byte) 0);
    ByteBuffer buf = ByteBuffer.wrap(data);
    buf.put((byte) pdu.getIcmp6Type().shortValue());
    buf.put((byte) pdu.getIcmp6Code().shortValue());
    buf.putShort((short) pdu.getIcmp6Chksum().intValue());
    buf.put((byte) pdu.getCurHopLimit().shortValue());
    buf.put((byte) pdu.getFlags().shortValue());
    buf.putShort((short) pdu.getRouterLifetime().intValue());
    buf.putInt((int) pdu.getReachableTime().longValue());
    buf.putInt((int) pdu.getRetransTime().longValue());
    buf.put((byte) pdu.getOptionSourceAddr().shortValue());
    buf.put((byte) pdu.getSourceAddrLength().shortValue());
    buf.put(Ipv6ServiceUtils.bytesFromHexString(pdu.getSourceLlAddress().getValue()));
    for (PrefixList prefix : pdu.getPrefixList()) {
        buf.put((byte) prefix.getOptionType().shortValue());
        buf.put((byte) prefix.getOptionLength().shortValue());
        buf.put((byte) prefix.getPrefixLength().shortValue());
        buf.put((byte) prefix.getFlags().shortValue());
        buf.putInt((int) prefix.getValidLifetime().longValue());
        buf.putInt((int) prefix.getPreferredLifetime().longValue());
        buf.putInt((int) prefix.getReserved().longValue());
        buf.put(IetfInetUtil.INSTANCE.ipv6PrefixToBytes(new Ipv6Prefix(prefix.getPrefix())), 0, 16);
    }
    return data;
}
Also used : PrefixList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.router.advertisement.packet.PrefixList) ByteBuffer(java.nio.ByteBuffer) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)

Aggregations

Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)63 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)20 ByteBuf (io.netty.buffer.ByteBuf)16 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)13 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)13 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)12 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)11 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)10 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec)8 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder)8 InetAddress (java.net.InetAddress)6 AceIpv6Builder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder)6 SourceIpv6PrefixCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCaseBuilder)6 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)6 Attributes1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder)6 MpReachNlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder)6 AdvertizedRoutesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder)6 IpPrefixSubobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject)6 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)5