Search in sources :

Example 46 with Ethernet

use of org.onlab.packet.Ethernet 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 47 with Ethernet

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

the class DefaultVirtualPacketProvider method virtualize.

/**
 * Translate the requested physical PacketContext into a virtual PacketContext.
 * See {@link org.onosproject.net.packet.PacketContext}
 *
 * @param context A physical PacketContext be translated
 * @return A translated virtual PacketContext
 */
private VirtualPacketContext virtualize(PacketContext context) {
    VirtualPort vPort = getMappedVirtualPort(context.inPacket().receivedFrom());
    if (vPort != null) {
        ConnectPoint cp = new ConnectPoint(vPort.element().id(), vPort.number());
        Ethernet eth = context.inPacket().parsed();
        eth.setVlanID(Ethernet.VLAN_UNTAGGED);
        InboundPacket inPacket = new DefaultInboundPacket(cp, eth, ByteBuffer.wrap(eth.serialize()));
        DefaultOutboundPacket outPkt = new DefaultOutboundPacket(cp.deviceId(), DefaultTrafficTreatment.builder().build(), ByteBuffer.wrap(eth.serialize()));
        VirtualPacketContext vContext = new DefaultVirtualPacketContext(context.time(), inPacket, outPkt, false, vPort.networkId(), this);
        return vContext;
    } else {
        return null;
    }
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Ethernet(org.onlab.packet.Ethernet) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) VirtualPacketContext(org.onosproject.incubator.net.virtual.VirtualPacketContext) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 48 with Ethernet

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

the class CastorArpManager method updateMac.

/**
 * Updates the IP address to mac address map.
 *
 * @param context The message context.
 */
private void updateMac(MessageContext context) {
    if ((castorStore.getAddressMap()).containsKey(context.sender())) {
        return;
    }
    Ethernet eth = context.packet();
    MacAddress macAddress = eth.getSourceMAC();
    IpAddress ipAddress = context.sender();
    castorStore.setAddressMap(ipAddress, macAddress);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress)

Example 49 with Ethernet

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

the class CastorArpManager method buildArpRequest.

/**
 * Builds the ARP request when MAC is not known.
 *
 * @param peer The Peer whose MAC is not known.
 * @return Ethernet
 */
private Ethernet buildArpRequest(Peer peer) {
    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET).setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH).setProtocolType(ARP.PROTO_TYPE_IP).setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH).setOpCode(ARP.OP_REQUEST);
    arp.setSenderHardwareAddress(ARP_SOURCEMAC.toBytes()).setSenderProtocolAddress(ARP_SRC.toOctets()).setTargetHardwareAddress(ZERO_MAC_ADDRESS).setTargetProtocolAddress(IpAddress.valueOf(peer.getIpAddress()).toOctets());
    Ethernet ethernet = new Ethernet();
    ethernet.setEtherType(Ethernet.TYPE_ARP).setDestinationMACAddress(MacAddress.BROADCAST).setSourceMACAddress(ARP_SOURCEMAC).setPayload(arp);
    ethernet.setPad(true);
    return ethernet;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ARP(org.onlab.packet.ARP) TYPE_ARP(org.onlab.packet.Ethernet.TYPE_ARP)

Example 50 with Ethernet

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

the class CastorArpManager method createArp.

@Override
public void createArp(Peer peer) {
    Ethernet packet = null;
    packet = buildArpRequest(peer);
    ByteBuffer buf = ByteBuffer.wrap(packet.serialize());
    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(peer.getPort());
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    builder.setOutput(connectPoint.port());
    packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), builder.build(), buf));
}
Also used : Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

Ethernet (org.onlab.packet.Ethernet)187 Test (org.junit.Test)91 ConnectPoint (org.onosproject.net.ConnectPoint)46 IPv4 (org.onlab.packet.IPv4)42 IPv6 (org.onlab.packet.IPv6)41 UDP (org.onlab.packet.UDP)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 MacAddress (org.onlab.packet.MacAddress)30 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)30 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)29 IpAddress (org.onlab.packet.IpAddress)28 OutboundPacket (org.onosproject.net.packet.OutboundPacket)26 DeviceId (org.onosproject.net.DeviceId)25 ByteBuffer (java.nio.ByteBuffer)24 DHCP (org.onlab.packet.DHCP)24 DHCP6 (org.onlab.packet.DHCP6)24 Interface (org.onosproject.net.intf.Interface)22 DeserializationException (org.onlab.packet.DeserializationException)20 ICMP6 (org.onlab.packet.ICMP6)20 InboundPacket (org.onosproject.net.packet.InboundPacket)20