Search in sources :

Example 41 with UDP

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

the class DhcpL2RelayTestBase method constructEthernetPacket.

private Ethernet constructEthernetPacket(MacAddress srcMac, MacAddress dstMac, String dstIp, byte dhcpReqRsp, MacAddress clientHwAddress, Ip4Address dhcpClientIpAddress, VlanId clientVlan, short clientPbit) {
    // Ethernet Frame.
    Ethernet ethPkt = new Ethernet();
    ethPkt.setSourceMACAddress(srcMac);
    ethPkt.setDestinationMACAddress(dstMac);
    ethPkt.setEtherType(Ethernet.TYPE_IPV4);
    ethPkt.setVlanID(clientVlan.toShort());
    ethPkt.setPriorityCode((byte) clientPbit);
    if (DHCP.OPCODE_REPLY == dhcpReqRsp) {
        ethPkt.setQinQPriorityCode((byte) 3);
        ethPkt.setQinQVID((short) 4);
    }
    // IP Packet
    IPv4 ipv4Reply = new IPv4();
    ipv4Reply.setSourceAddress(0);
    ipv4Reply.setDestinationAddress(dstIp);
    ipv4Reply.setTtl((byte) 127);
    // UDP Datagram.
    UDP udpReply = new UDP();
    udpReply.setSourcePort((byte) UDP.DHCP_CLIENT_PORT);
    udpReply.setDestinationPort((byte) UDP.DHCP_SERVER_PORT);
    // DHCP Payload.
    DHCP dhcpReply = new DHCP();
    dhcpReply.setOpCode(dhcpReqRsp);
    dhcpReply.setYourIPAddress(dhcpClientIpAddress.toInt());
    dhcpReply.setServerIPAddress(0);
    final byte[] serverNameBytes = new byte[64];
    String result = new String(serverNameBytes, StandardCharsets.US_ASCII).trim();
    dhcpReply.setServerName(result);
    final byte[] bootFileBytes = new byte[128];
    String result1 = new String(bootFileBytes, StandardCharsets.US_ASCII).trim();
    dhcpReply.setBootFileName(result1);
    dhcpReply.setTransactionId(TRANSACTION_ID);
    dhcpReply.setClientHardwareAddress(clientHwAddress.toBytes());
    dhcpReply.setHardwareType(DHCP.HWTYPE_ETHERNET);
    dhcpReply.setHardwareAddressLength((byte) 6);
    udpReply.setPayload(dhcpReply);
    ipv4Reply.setPayload(udpReply);
    ethPkt.setPayload(ipv4Reply);
    return ethPkt;
}
Also used : UDP(org.onlab.packet.UDP) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) DHCP(org.onlab.packet.DHCP)

Example 42 with UDP

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

the class DhcpL2RelayTestBase method constructDhcpRequestPacket.

/**
 * Constructs DHCP Request Packet.
 *
 * @return Ethernet packet
 */
Ethernet constructDhcpRequestPacket(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.DHCPREQUEST));
    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 43 with UDP

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

the class DhcpL2RelayTestBase method constructDhcpDiscoverPacket.

/**
 * Constructs DHCP Discover Packet with client VLAN information.
 *
 * @return Ethernet packet
 */
Ethernet constructDhcpDiscoverPacket(MacAddress clientMac, VlanId clientVlan, short clientPbit) {
    Ethernet pkt = constructEthernetPacket(clientMac, MacAddress.BROADCAST, "255.255.255.255", DHCP.OPCODE_REQUEST, clientMac, Ip4Address.valueOf("0.0.0.0"), clientVlan, clientPbit);
    IPv4 ipv4Packet = (IPv4) pkt.getPayload();
    UDP udpPacket = (UDP) ipv4Packet.getPayload();
    DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
    dhcpPacket.setOptions(constructDhcpOptions(DHCP.MsgType.DHCPDISCOVER));
    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 44 with UDP

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

the class DhcpL2RelayTestBase method constructDhcpNakPacket.

/**
 * Constructs DHCP Nak Packet.
 *
 * @return Ethernet packet
 */
Ethernet constructDhcpNakPacket(MacAddress servMac, MacAddress clientMac, String ipAddress, String dhcpClientIpAddress, VlanId clientVlan, short clientPcp) {
    Ethernet pkt = constructEthernetPacket(servMac, clientMac, ipAddress, DHCP.OPCODE_REPLY, clientMac, Ip4Address.valueOf(dhcpClientIpAddress), clientVlan, clientPcp);
    IPv4 ipv4Packet = (IPv4) pkt.getPayload();
    UDP udpPacket = (UDP) ipv4Packet.getPayload();
    DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
    dhcpPacket.setOptions(constructDhcpOptions(DHCP.MsgType.DHCPNAK));
    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 45 with UDP

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

the class DhcpL2RelayTestBase method constructDhcpAckPacket.

/**
 * Constructs DHCP Ack Packet.
 *
 * @return Ethernet packet
 */
Ethernet constructDhcpAckPacket(MacAddress servMac, MacAddress clientMac, String ipAddress, String dhcpClientIpAddress) {
    Ethernet pkt = construcEthernetPacket(servMac, clientMac, ipAddress, DHCP.OPCODE_REPLY, clientMac, Ip4Address.valueOf(dhcpClientIpAddress));
    IPv4 ipv4Packet = (IPv4) pkt.getPayload();
    UDP udpPacket = (UDP) ipv4Packet.getPayload();
    DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
    dhcpPacket.setOptions(constructDhcpOptions(DHCP.MsgType.DHCPACK));
    return pkt;
}
Also used : UDP(org.onlab.packet.UDP) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) DHCP(org.onlab.packet.DHCP)

Aggregations

UDP (org.onlab.packet.UDP)46 Ethernet (org.onlab.packet.Ethernet)36 IPv4 (org.onlab.packet.IPv4)24 DHCP (org.onlab.packet.DHCP)19 IPv6 (org.onlab.packet.IPv6)17 DHCP6 (org.onlab.packet.DHCP6)16 ConnectPoint (org.onosproject.net.ConnectPoint)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 MacAddress (org.onlab.packet.MacAddress)10 Interface (org.onosproject.net.intf.Interface)9 VlanId (org.onlab.packet.VlanId)8 DhcpOption (org.onlab.packet.dhcp.DhcpOption)8 DhcpServerInfo (org.onosproject.dhcprelay.api.DhcpServerInfo)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 IpAddress (org.onlab.packet.IpAddress)7 DeviceId (org.onosproject.net.DeviceId)7 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)7 TrafficSelector (org.onosproject.net.flow.TrafficSelector)7