Search in sources :

Example 16 with Ethernet

use of org.onlab.packet.Ethernet in project dhcpl2relay by opencord.

the class DhcpL2RelayTestBase method constructDhcpDiscoverPacket.

/**
 * Constructs DHCP Discover Packet.
 *
 * @return Ethernet packet
 */
Ethernet constructDhcpDiscoverPacket(MacAddress clientMac) {
    Ethernet pkt = construcEthernetPacket(clientMac, MacAddress.BROADCAST, "255.255.255.255", DHCP.OPCODE_REQUEST, clientMac, Ip4Address.valueOf("0.0.0.0"));
    IPv4 ipv4Packet = (IPv4) pkt.getPayload();
    UDP udpPacket = (UDP) ipv4Packet.getPayload();
    DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
    dhcpPacket.setOptions(constructDhcpOptions(DHCP.MsgType.DHCPDISCOVER));
    log.info("Sending discover packet {}", dhcpPacket.getOptions());
    return pkt;
}
Also used : UDP(org.onlab.packet.UDP) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) DHCP(org.onlab.packet.DHCP)

Example 17 with Ethernet

use of org.onlab.packet.Ethernet in project aaa by opencord.

the class PortBasedRadiusCommunicator method sendRadiusPacket.

@Override
public void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) {
    // create the packet
    Ethernet ethReply = new Ethernet();
    ethReply.setSourceMACAddress(nasMacAddress);
    ethReply.setDestinationMACAddress(radiusMacAddress);
    ethReply.setEtherType(Ethernet.TYPE_IPV4);
    ethReply.setVlanID(radiusVlanID);
    ethReply.setPriorityCode(radiusPBit);
    IPv4 ipv4Packet = new IPv4();
    ipv4Packet.setTtl((byte) 64);
    ipv4Packet.setSourceAddress(Ip4Address.valueOf(nasIpAddress).toInt());
    ipv4Packet.setDestinationAddress(Ip4Address.valueOf(radiusIpAddress).toInt());
    UDP udpPacket = new UDP();
    udpPacket.setSourcePort(radiusServerPort);
    udpPacket.setDestinationPort(radiusServerPort);
    udpPacket.setPayload(radiusPacket);
    ipv4Packet.setPayload(udpPacket);
    ethReply.setPayload(ipv4Packet);
    // store the IP address and SN of the device, later to be used
    // for ARP responses
    String serialNo = deviceService.getDevice(inPkt.receivedFrom().deviceId()).serialNumber();
    if (subsService == null) {
        log.warn(SADIS_NOT_RUNNING);
        aaaManager.radiusOperationalStatusService.setStatusServerReqSent(false);
        return;
    }
    SubscriberAndDeviceInformation deviceInfo = subsService.get(serialNo);
    if (deviceInfo == null) {
        log.warn("No Device found with SN {}", serialNo);
        aaaManager.radiusOperationalStatusService.setStatusServerReqSent(false);
        return;
    }
    if (radiusPacket.getIdentifier() == RadiusOperationalStatusManager.AAA_REQUEST_ID_STATUS_REQUEST || radiusPacket.getIdentifier() == RadiusOperationalStatusManager.AAA_REQUEST_ID_FAKE_ACCESS_REQUEST) {
        aaaManager.radiusOperationalStatusService.setOutTimeInMillis(radiusPacket.getIdentifier());
    } else {
        aaaManager.aaaStatisticsManager.putOutgoingIdentifierToMap(radiusPacket.getIdentifier());
    }
    Ip4Address ipAddress = deviceInfo.ipAddress();
    if (ipAddress != null) {
        ipToSnMap.put(ipAddress, serialNo);
    } else {
        log.warn("Cannot Map IpAddress to SerialNo : ipAddress = {}", ipAddress);
    }
    // send the message out
    sendFromRadiusServerPort(pktCustomizer.customizeEthernetIPHeaders(ethReply, inPkt));
    aaaManager.radiusOperationalStatusService.setStatusServerReqSent(true);
}
Also used : UDP(org.onlab.packet.UDP) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) Ip4Address(org.onlab.packet.Ip4Address) SubscriberAndDeviceInformation(org.opencord.sadis.SubscriberAndDeviceInformation)

Example 18 with Ethernet

use of org.onlab.packet.Ethernet in project aaa by opencord.

the class PortBasedRadiusCommunicator method handleIPv4PacketFromServer.

/**
 * Handles IP packets from RADIUS server.
 *
 * @param context Context for the packet
 */
private void handleIPv4PacketFromServer(PacketContext context) {
    // Extract the original Ethernet frame from the packet information
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
    if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) {
        UDP udpPacket = (UDP) ipv4Packet.getPayload();
        if (udpPacket.getSourcePort() == radiusServerPort) {
            // This packet is RADIUS packet from the server.
            RADIUS radiusMsg;
            try {
                radiusMsg = RADIUS.deserializer().deserialize(udpPacket.serialize(), 8, udpPacket.getLength() - 8);
                aaaManager.aaaStatisticsManager.handleRoundtripTime(radiusMsg.getIdentifier());
                aaaManager.handleRadiusPacket(radiusMsg);
            } catch (DeserializationException dex) {
                log.error("Cannot deserialize packet", dex);
            }
        }
    }
}
Also used : UDP(org.onlab.packet.UDP) RADIUS(org.onlab.packet.RADIUS) InboundPacket(org.onosproject.net.packet.InboundPacket) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) DeserializationException(org.onlab.packet.DeserializationException)

Example 19 with Ethernet

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

the class IcmpHandlerTest method testPing6RemoteGatewayLeafDown.

// Ping6 to a gateway but destination leaf is down
@Test
public void testPing6RemoteGatewayLeafDown() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF)).andReturn(false).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmpv6(ETH_REQ_IPV6, CP11);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6.getSourceMAC());
    assertNull(ethernet);
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) Test(org.junit.Test)

Example 20 with Ethernet

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

the class IcmpHandlerTest method testPing4Loopback.

// Ping to the looback of our leaf
@Test
public void testPing4Loopback() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK, CP12);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

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