Search in sources :

Example 11 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class KubevirtNetworkingUtil method buildGarpPacket.

/**
 * Builds a GARP packet using the given source MAC and source IP address.
 *
 * @param srcMac source MAC address
 * @param srcIp  source IP address
 * @return GARP packet
 */
public static Ethernet buildGarpPacket(MacAddress srcMac, IpAddress srcIp) {
    if (srcMac == null || srcIp == null) {
        return null;
    }
    Ethernet ethernet = new Ethernet();
    ethernet.setDestinationMACAddress(MacAddress.BROADCAST);
    ethernet.setSourceMACAddress(srcMac);
    ethernet.setEtherType(Ethernet.TYPE_ARP);
    ARP arp = new ARP();
    arp.setOpCode(ARP.OP_REPLY);
    arp.setProtocolType(ARP.PROTO_TYPE_IP);
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
    arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
    arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
    arp.setSenderHardwareAddress(srcMac.toBytes());
    arp.setTargetHardwareAddress(MacAddress.BROADCAST.toBytes());
    arp.setSenderProtocolAddress(srcIp.toOctets());
    arp.setTargetProtocolAddress(srcIp.toOctets());
    ethernet.setPayload(arp);
    return ethernet;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ARP(org.onlab.packet.ARP)

Example 12 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class OpenstackNetworkingUtil method buildGratuitousArpPacket.

/**
 * Returns GARP packet with supplied floating ip and instance port information.
 *
 * @param floatingIP floating ip
 * @param instancePort instance port
 * @param vlanId vlan id
 * @return GARP packet
 */
private static Ethernet buildGratuitousArpPacket(NetFloatingIP floatingIP, InstancePort instancePort, VlanId vlanId) {
    Ethernet ethernet = new Ethernet();
    ethernet.setDestinationMACAddress(MacAddress.BROADCAST);
    ethernet.setSourceMACAddress(instancePort.macAddress());
    ethernet.setEtherType(Ethernet.TYPE_ARP);
    ethernet.setVlanID(vlanId.id());
    ARP arp = new ARP();
    arp.setOpCode(ARP.OP_REPLY);
    arp.setProtocolType(ARP.PROTO_TYPE_IP);
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
    arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
    arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
    arp.setSenderHardwareAddress(instancePort.macAddress().toBytes());
    arp.setTargetHardwareAddress(MacAddress.BROADCAST.toBytes());
    arp.setSenderProtocolAddress(valueOf(floatingIP.getFloatingIpAddress()).toInt());
    arp.setTargetProtocolAddress(valueOf(floatingIP.getFloatingIpAddress()).toInt());
    ethernet.setPayload(arp);
    return ethernet;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ARP(org.onlab.packet.ARP)

Example 13 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class OpenstackSwitchingArpHandler method setFakeGatewayArpRule.

/**
 * Installs flow rules which convert ARP request packet into ARP reply
 * by adding a fake gateway MAC address as Source Hardware Address.
 *
 * @param osSubnet  openstack subnet
 * @param network   openstack network
 * @param install   flag which indicates whether to install rule or remove rule
 * @param osNode    openstack node
 */
private void setFakeGatewayArpRule(Subnet osSubnet, Network network, boolean install, OpenstackNode osNode) {
    if (ARP_BROADCAST_MODE.equals(getArpMode())) {
        Type netType = osNetworkService.networkType(network.getId());
        String gateway = osSubnet.getGateway();
        if (gateway == null) {
            return;
        }
        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
        if (netType == VLAN) {
            sBuilder.matchVlanId(VlanId.vlanId(network.getProviderSegID()));
        } else if (netType == VXLAN || netType == GRE || netType == GENEVE) {
            // different networks
            if (!install) {
                long numOfDupGws = osNetworkService.subnets().stream().filter(s -> !s.getId().equals(osSubnet.getId())).filter(s -> s.getGateway() != null).filter(s -> s.getGateway().equals(osSubnet.getGateway())).count();
                if (numOfDupGws > 0) {
                    return;
                }
            }
        }
        sBuilder.matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(gateway));
        if (osNode == null) {
            osNodeService.completeNodes(COMPUTE).forEach(n -> {
                Device device = deviceService.getDevice(n.intgBridge());
                TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
                if (netType == VLAN) {
                    tBuilder.popVlan();
                }
                tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setEthSrc(MacAddress.valueOf(gatewayMac)).setOutput(PortNumber.IN_PORT);
                osFlowRuleService.setRule(appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
            });
        } else {
            Device device = deviceService.getDevice(osNode.intgBridge());
            TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
            if (netType == VLAN) {
                tBuilder.popVlan();
            }
            tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setOutput(PortNumber.IN_PORT);
            osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
        }
    }
}
Also used : OpenstackGroupRuleService(org.onosproject.openstacknetworking.api.OpenstackGroupRuleService) CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ARP(org.onlab.packet.ARP) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) PRIORITY_ARP_REQUEST_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REQUEST_RULE) InstancePortEvent(org.onosproject.openstacknetworking.api.InstancePortEvent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) PRIORITY_ARP_REPLY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REPLY_RULE) Ethernet(org.onlab.packet.Ethernet) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) VLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) RulePopulatorUtil.buildMoveEthSrcToDstExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveEthSrcToDstExtension) RulePopulatorUtil.buildMoveArpShaToThaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpShaToThaExtension) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) ALL(org.onosproject.net.group.GroupDescription.Type.ALL) GRE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Ip4Address(org.onlab.packet.Ip4Address) Device(org.onosproject.net.Device) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) ARP_PROXY_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_PROXY_MODE) Deactivate(org.osgi.service.component.annotations.Deactivate) PRIORITY_ARP_GROUP_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GROUP_RULE) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) InstancePortListener(org.onosproject.openstacknetworking.api.InstancePortListener) NetworkType(org.openstack4j.model.network.NetworkType) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) PacketContext(org.onosproject.net.packet.PacketContext) OpenstackNetworkingUtil.swapStaleLocation(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.swapStaleLocation) ClusterService(org.onosproject.cluster.ClusterService) ARP_MODE_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE_DEFAULT) OpenstackNetworkingUtil.tunnelPortNumByNetId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetId) Dictionary(java.util.Dictionary) IdEntity(org.openstack4j.model.common.IdEntity) Tools(org.onlab.util.Tools) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) GATEWAY_MAC_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC_DEFAULT) ComponentContext(org.osgi.service.component.ComponentContext) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) GroupBucket(org.onosproject.net.group.GroupBucket) RulePopulatorUtil.buildMoveArpSpaToTpaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpSpaToTpaExtension) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) GATEWAY_MAC(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC) ARP_TABLE(org.onosproject.openstacknetworking.api.Constants.ARP_TABLE) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ARP_MODE(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) GENEVE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GENEVE) Subnet(org.openstack4j.model.network.Subnet) PRIORITY_ARP_GATEWAY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GATEWAY_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) GroupId(org.onosproject.core.GroupId) ConfigProperty(org.onosproject.cfg.ConfigProperty) Modified(org.osgi.service.component.annotations.Modified) MacAddress(org.onlab.packet.MacAddress) VXLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN) Reference(org.osgi.service.component.annotations.Reference) PRIORITY_ARP_CONTROL_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_CONTROL_RULE) LeadershipService(org.onosproject.cluster.LeadershipService) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) RulePopulatorUtil.buildGroupBucket(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildGroupBucket) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) NetworkType(org.openstack4j.model.network.NetworkType) EthType(org.onlab.packet.EthType) Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 14 with ARP

use of org.onlab.packet.ARP in project trellis-control by opennetworkinglab.

the class ArpHandler method validateArpSpa.

/**
 * Check if the source protocol address of an ARP packet belongs to the same
 * subnet configured on the port it is seen.
 *
 * @param pkt ARP packet and context information
 * @return true if the source protocol address belongs to the configured subnet
 */
private boolean validateArpSpa(NeighbourMessageContext pkt) {
    Ip4Address spa = pkt.sender().getIp4Address();
    Set<IpPrefix> subnet = config.getPortSubnets(pkt.inPort().deviceId(), pkt.inPort().port()).stream().filter(ipPrefix -> ipPrefix.isIp4() && ipPrefix.contains(spa)).collect(Collectors.toSet());
    return !subnet.isEmpty();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) LoggerFactory(org.slf4j.LoggerFactory) ARP(org.onlab.packet.ARP) Set(java.util.Set) HostService(org.onosproject.net.host.HostService) Collectors(java.util.stream.Collectors) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) REQUEST(org.onosproject.net.neighbour.NeighbourMessageType.REQUEST) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) NeighbourMessageContext(org.onosproject.net.neighbour.NeighbourMessageContext) Ip4Address(org.onlab.packet.Ip4Address)

Example 15 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class DhcpRelayManagerTest method testArpRequest.

@Test
public void testArpRequest() throws Exception {
    packetService.processPacket(new TestArpRequestPacketContext(CLIENT_INTERFACE));
    assertAfter(PKT_PROCESSING_MS, () -> assertNotNull(packetService.emittedPacket));
    OutboundPacket outboundPacket = packetService.emittedPacket;
    byte[] outPacketData = outboundPacket.data().array();
    Ethernet eth = Ethernet.deserializer().deserialize(outPacketData, 0, outPacketData.length);
    assertAfter(PKT_PROCESSING_MS, () -> assertEquals(eth.getEtherType(), Ethernet.TYPE_ARP));
    ARP arp = (ARP) eth.getPayload();
    assertAfter(PKT_PROCESSING_MS, () -> assertArrayEquals(arp.getSenderHardwareAddress(), CLIENT_INTERFACE.mac().toBytes()));
}
Also used : Ethernet(org.onlab.packet.Ethernet) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ARP(org.onlab.packet.ARP) Test(org.junit.Test)

Aggregations

ARP (org.onlab.packet.ARP)22 Ethernet (org.onlab.packet.Ethernet)17 IpAddress (org.onlab.packet.IpAddress)10 MacAddress (org.onlab.packet.MacAddress)9 Ip4Address (org.onlab.packet.Ip4Address)7 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)7 Set (java.util.Set)6 ConnectPoint (org.onosproject.net.ConnectPoint)6 DeviceId (org.onosproject.net.DeviceId)6 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)6 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)6 Logger (org.slf4j.Logger)6 ByteBuffer (java.nio.ByteBuffer)5 Collectors (java.util.stream.Collectors)5 VlanId (org.onlab.packet.VlanId)5 PacketService (org.onosproject.net.packet.PacketService)5 Objects (java.util.Objects)4 ExecutorService (java.util.concurrent.ExecutorService)4 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)4 Test (org.junit.Test)4