Search in sources :

Example 1 with RouterAdvertisementPacketBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.RouterAdvertisementPacketBuilder in project netvirt by opendaylight.

the class Ipv6RouterAdvt method transmitRtrAdvertisement.

public boolean transmitRtrAdvertisement(Ipv6RouterAdvertisementType raType, VirtualPort routerPort, long elanTag, @Nullable RouterSolicitationPacket rsPdu, Uint64 dpnId, Uuid port, long ipv6RouterReachableTime) {
    RouterAdvertisementPacketBuilder raPacket = new RouterAdvertisementPacketBuilder();
    updateRAResponse(raType, rsPdu, raPacket, routerPort, ipv6RouterReachableTime);
    // Serialize the response packet
    byte[] txPayload = fillRouterAdvertisementPacket(raPacket.build());
    TransmitPacketInput input = null;
    /* Send solicited router advertisement to requested VM port only.
         * Send periodic unsolicited router advertisement to ELAN broadcast group.
         */
    if (raType == Ipv6RouterAdvertisementType.SOLICITED_ADVERTISEMENT) {
        List<Action> actions = ifMgr.getEgressAction(port.getValue());
        if (actions == null || actions.isEmpty()) {
            LOG.error("Unable to send solicited router advertisement packet out. Since Egress " + "action is empty for interface {}. ", port.getValue());
            return false;
        }
        input = MDSALUtil.getPacketOut(actions, txPayload, dpnId);
        LOG.debug("Transmitting the Router Advt packet out to port {}", port.getValue());
    } else {
        /* Here we handle UNSOLICITED_ADVERTISEMENT, CEASE_ADVERTISEMENT */
        long elanGroupId = Ipv6ServiceUtils.getRemoteBCGroup(elanTag);
        List<ActionInfo> lstActionInfo = new ArrayList<>();
        lstActionInfo.add(new ActionGroup(elanGroupId));
        input = MDSALUtil.getPacketOutDefault(lstActionInfo, txPayload, dpnId);
        LOG.debug("Transmitting the Router Advt packet out to ELAN Group ID {}", elanGroupId);
    }
    LoggingFutures.addErrorLogging(packetService.transmitPacket(input), LOG, "transmitPacket");
    return true;
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) ArrayList(java.util.ArrayList) RouterAdvertisementPacketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.RouterAdvertisementPacketBuilder) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo)

Example 2 with RouterAdvertisementPacketBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.RouterAdvertisementPacketBuilder in project netvirt by opendaylight.

the class Ipv6RouterAdvt method transmitRtrAdvertisement.

public boolean transmitRtrAdvertisement(Ipv6RtrAdvertType raType, VirtualPort routerPort, List<NodeConnectorRef> outportList, RouterSolicitationPacket rsPdu) {
    RouterAdvertisementPacketBuilder raPacket = new RouterAdvertisementPacketBuilder();
    updateRAResponse(raType, rsPdu, raPacket, routerPort);
    // Serialize the response packet
    byte[] txPayload = fillRouterAdvertisementPacket(raPacket.build());
    for (NodeConnectorRef outport : outportList) {
        InstanceIdentifier<Node> outNode = outport.getValue().firstIdentifierOf(Node.class);
        TransmitPacketInput input = new TransmitPacketInputBuilder().setPayload(txPayload).setNode(new NodeRef(outNode)).setEgress(outport).build();
        LOG.debug("Transmitting the Router Advt packet out {}", outport);
        JdkFutures.addErrorLogging(packetService.transmitPacket(input), LOG, "transmitPacket");
    }
    return true;
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) RouterAdvertisementPacketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.RouterAdvertisementPacketBuilder)

Example 3 with RouterAdvertisementPacketBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.RouterAdvertisementPacketBuilder 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 4 with RouterAdvertisementPacketBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.RouterAdvertisementPacketBuilder in project netvirt by opendaylight.

the class Ipv6RouterAdvt method updateRAResponse.

private static void updateRAResponse(Ipv6RouterAdvertisementType raType, @Nullable RouterSolicitationPacket pdu, RouterAdvertisementPacketBuilder raPacket, VirtualPort routerPort, long ipv6RouterReachableTime) {
    short icmpv6RaFlags = 0;
    String gatewayMac = null;
    IpAddress gatewayIp;
    List<Ipv6Prefix> autoConfigPrefixList = new ArrayList<>();
    List<Ipv6Prefix> 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 (Ipv6ServiceConstants.IPV6_AUTO_ADDRESS_SUBNETS.contains(subnet.getIpv6RAMode())) {
                autoConfigPrefixList.add(requireNonNull(subnet.getSubnetCidr().getIpv6Prefix()));
            }
            if (subnet.getIpv6RAMode().equalsIgnoreCase(Ipv6ServiceConstants.IPV6_DHCPV6_STATEFUL)) {
                statefulConfigPrefixList.add(requireNonNull(subnet.getSubnetCidr().getIpv6Prefix()));
            }
        }
        if (subnet.getIpv6RAMode().equalsIgnoreCase(Ipv6ServiceConstants.IPV6_DHCPV6_STATELESS)) {
            // Other Configuration.
            icmpv6RaFlags = (short) (icmpv6RaFlags | 1 << 6);
        } else if (subnet.getIpv6RAMode().equalsIgnoreCase(Ipv6ServiceConstants.IPV6_DHCPV6_STATEFUL)) {
            // Managed Address Conf.
            icmpv6RaFlags = (short) (icmpv6RaFlags | 1 << 7);
        }
    }
    gatewayMac = routerPort.getMacAddress();
    MacAddress sourceMac = MacAddress.getDefaultInstance(gatewayMac);
    raPacket.setSourceMac(sourceMac);
    if (raType == Ipv6RouterAdvertisementType.SOLICITED_ADVERTISEMENT) {
        if (pdu == null) {
            throw new IllegalArgumentException("Null pdu for solicited advertisement");
        }
        raPacket.setDestinationMac(pdu.getSourceMac());
        raPacket.setDestinationIpv6(pdu.getSourceIpv6());
        raPacket.setFlowLabel(pdu.getFlowLabel());
    } else {
        raPacket.setDestinationMac(new MacAddress(Ipv6Constants.ALL_NODES_MCAST_MAC));
        raPacket.setDestinationIpv6(Ipv6ServiceUtils.ALL_NODES_MCAST_ADDR);
        raPacket.setFlowLabel(Ipv6ServiceConstants.DEF_FLOWLABEL);
    }
    raPacket.setEthertype(NwConstants.ETHTYPE_IPV6);
    raPacket.setVersion(Ipv6Constants.IPV6_VERSION);
    int prefixListLength = autoConfigPrefixList.size() + statefulConfigPrefixList.size();
    int mtuOptionLength = routerPort.getMtu() == 0 ? 0 : Ipv6Constants.ICMPV6_OPTION_MTU_LENGTH;
    raPacket.setIpv6Length(Ipv6Constants.ICMPV6_RA_LENGTH_WO_OPTIONS + mtuOptionLength + Ipv6Constants.ICMPV6_OPTION_SOURCE_LLA_LENGTH + prefixListLength * Ipv6Constants.ICMPV6_OPTION_PREFIX_LENGTH);
    raPacket.setNextHeader(IPProtocols.IPV6ICMP.shortValue());
    raPacket.setHopLimit(Ipv6Constants.ICMP_V6_MAX_HOP_LIMIT);
    raPacket.setSourceIpv6(Ipv6Util.getIpv6LinkLocalAddressFromMac(sourceMac));
    raPacket.setIcmp6Type(Icmpv6Type.ROUTER_ADVETISEMENT.getValue());
    raPacket.setIcmp6Code((short) 0);
    raPacket.setIcmp6Chksum(0);
    raPacket.setCurHopLimit((short) Ipv6Constants.IPV6_DEFAULT_HOP_LIMIT);
    raPacket.setFlags(icmpv6RaFlags);
    if (raType == Ipv6RouterAdvertisementType.CEASE_ADVERTISEMENT) {
        raPacket.setRouterLifetime(0);
    } else {
        raPacket.setRouterLifetime(Ipv6Constants.IPV6_ROUTER_LIFETIME);
    }
    if (ipv6RouterReachableTime == 0L) {
        raPacket.setReachableTime((long) Ipv6Constants.IPV6_RA_REACHABLE_TIME);
    } else {
        raPacket.setReachableTime(ipv6RouterReachableTime);
    }
    raPacket.setRetransTime((long) 0);
    raPacket.setOptionSourceAddr(Ipv6Constants.ICMP_V6_OPTION_SOURCE_LLA);
    raPacket.setSourceAddrLength((short) 1);
    raPacket.setSourceLlAddress(MacAddress.getDefaultInstance(gatewayMac));
    if (mtuOptionLength != 0) {
        raPacket.setOptionMtu(Ipv6Constants.ICMP_V6_OPTION_MTU);
        raPacket.setOptionMtuLength((short) 1);
        raPacket.setMtu((long) routerPort.getMtu());
    }
    List<PrefixList> prefixList = new ArrayList<>();
    PrefixListBuilder prefix = new PrefixListBuilder();
    prefix.setOptionType(Ipv6Constants.ICMP_V6_OPTION_PREFIX_INFO);
    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 (Ipv6Prefix v6Prefix : autoConfigPrefixList) {
        prefix.setFlags(autoConfPrefixFlags);
        prefix.setPrefix(v6Prefix);
        prefixList.add(prefix.build());
    }
    short statefulPrefixFlags = 0;
    // On-link flag
    statefulPrefixFlags = (short) (statefulPrefixFlags | 1 << 7);
    for (Ipv6Prefix v6Prefix : statefulConfigPrefixList) {
        prefix.setFlags(statefulPrefixFlags);
        prefix.setPrefix(v6Prefix);
        prefixList.add(prefix.build());
    }
    raPacket.setPrefixList(prefixList);
}
Also used : ArrayList(java.util.ArrayList) PrefixListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.router.advertisement.packet.PrefixListBuilder) 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) 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.genius.ipv6.nd.packet.rev160620.router.advertisement.packet.PrefixList)

Aggregations

ArrayList (java.util.ArrayList)3 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)2 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)2 TransmitPacketInput (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput)2 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)1 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)1 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)1 RouterAdvertisementPacketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.RouterAdvertisementPacketBuilder)1 PrefixList (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.router.advertisement.packet.PrefixList)1 PrefixListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.packet.rev160620.router.advertisement.packet.PrefixListBuilder)1 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)1 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)1 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)1 RouterAdvertisementPacketBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.RouterAdvertisementPacketBuilder)1 PrefixList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.router.advertisement.packet.PrefixList)1 PrefixListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.router.advertisement.packet.PrefixListBuilder)1 TransmitPacketInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder)1