Java Code Examples for org.onlab.packet.Ethernet#duplicate()

The following examples show how to use org.onlab.packet.Ethernet#duplicate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Dhcp4HandlerImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Removes DHCP relay agent information option (option 82) from DHCP payload.
 * Also reset giaddr to 0
 *
 * @param ethPacket the Ethernet packet to be processed
 * @return Ethernet packet processed
 */
private Ethernet removeRelayAgentOption(Ethernet ethPacket) {
    Ethernet ethernet = (Ethernet) ethPacket.duplicate();
    IPv4 ipv4 = (IPv4) ethernet.getPayload();
    UDP udp = (UDP) ipv4.getPayload();
    DHCP dhcpPayload = (DHCP) udp.getPayload();

    // removes relay agent information option
    List<DhcpOption> options = dhcpPayload.getOptions();
    options = options.stream()
            .filter(option -> option.getCode() != OptionCode_CircuitID.getValue())
            .collect(Collectors.toList());
    dhcpPayload.setOptions(options);
    dhcpPayload.setGatewayIPAddress(0);

    udp.setPayload(dhcpPayload);
    ipv4.setPayload(udp);
    ethernet.setPayload(ipv4);
    return ethernet;
}
 
Example 2
Source File: DefaultNeighbourMessageActionsTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void forwardToInterface() {
    Ethernet request = NeighbourTestUtils.createArpRequest(IP1);

    Ethernet forwardedRequest = request.duplicate();
    forwardedRequest.setSourceMACAddress(INTF2.mac());
    forwardedRequest.setVlanID(INTF2.vlan().toShort());

    packetService.emit(outbound(forwardedRequest, CP2));
    expectLastCall().once();
    replay(packetService);

    actions.forward(createContext(request, CP1, null), INTF2);

    verify(packetService);
}