use of org.onlab.packet.DHCP in project dhcpl2relay by opencord.
the class DhcpL2RelayTest method compareServerPackets.
public void compareServerPackets(Ethernet sent, Ethernet relayed, VlanId expectedVlan, short expectedPcp) {
try {
// modify sent packet to create expected packet
sent.setDestinationMACAddress(CLIENT_MAC);
sent.setQinQVID(NOT_PROVIDED);
sent.setQinQPriorityCode((byte) NOT_PROVIDED);
sent.setVlanID(expectedVlan.toShort());
sent.setPriorityCode((byte) expectedPcp);
DHCP d = ((DHCP) ((UDP) ((IPv4) sent.getPayload()).getPayload()).getPayload());
List<DhcpOption> newOptions = d.getOptions().stream().filter(option -> option.getCode() != DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue()).collect(Collectors.toList());
d.setOptions(newOptions);
final ByteBuffer byteBuffer = ByteBuffer.wrap(sent.serialize());
Ethernet expectedPacket = Ethernet.deserializer().deserialize(byteBuffer.array(), 0, byteBuffer.array().length);
assertEquals(expectedPacket, relayed);
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
}
use of org.onlab.packet.DHCP in project dhcpl2relay by opencord.
the class DhcpL2Relay method activate.
@Activate
protected void activate(ComponentContext context) {
// start the dhcp relay agent
appId = coreService.registerApplication(DHCP_L2RELAY_APP);
componentConfigService.registerProperties(getClass());
eventDispatcher.addSink(DhcpL2RelayEvent.class, listenerRegistry);
KryoNamespace serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(Instant.class).register(DHCP.MsgType.class).register(DhcpAllocationInfo.class).build();
allocations = storageService.<String, DhcpAllocationInfo>consistentMapBuilder().withName("dhcpl2relay-allocations").withSerializer(Serializer.using(serializer)).withApplicationId(appId).build();
dhcpL2RelayCounters.setDelegate(delegate);
eventHandlerExecutor = newSingleThreadExecutor(groupedThreads("onos/dhcp", "dhcp-event-%d", log));
cfgService.addListener(cfgListener);
mastershipService.addListener(changeListener);
deviceService.addListener(deviceListener);
if (sadisService != null) {
subsService = sadisService.getSubscriberInfoService();
} else {
log.warn(SADIS_NOT_RUNNING);
}
factories.forEach(cfgService::registerConfigFactory);
// update the dhcp server configuration.
updateConfig();
if (context != null) {
modified(context);
}
// add the packet services.
packetService.addProcessor(dhcpRelayPacketProcessor, PacketProcessor.director(0));
log.info("DHCP-L2-RELAY Started");
}
use of org.onlab.packet.DHCP 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;
}
use of org.onlab.packet.DHCP 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;
}
use of org.onlab.packet.DHCP 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;
}
Aggregations