Package org.dhcp4java

Examples of org.dhcp4java.DHCPPacket


    }
   
    @Test
    public void testGetMirrorValue() {
      DHCPOption mirrorOpt;
      DHCPPacket pac = new DHCPPacket();
      assertEquals(opt, opt.applyOption(pac));
     
      pac.setOptionAsInt(DHO_DHCP_LEASE_TIME, 86400);
     
      mirrorOpt = opt.applyOption(pac);
      assertEquals(DHO_DHCP_LEASE_TIME, mirrorOpt.getCode());
      assertTrue(Arrays.equals(DHCPOption.int2Bytes(86400), mirrorOpt.getValue()));
     
      pac.setOptionRaw(DHO_DHCP_LEASE_TIME, new byte[0]);
      mirrorOpt = opt.applyOption(pac);
      assertEquals(DHO_DHCP_LEASE_TIME, mirrorOpt.getCode());
      assertTrue(Arrays.equals(new byte[0], mirrorOpt.getValue()));
    }
View Full Code Here


   
    @Test
    public void testGetMirrorValueIfMirrorIsFalse() {
      DHCPOption opt2 = new DHCPOption(DHO_DHCP_LEASE_TIME, null, false);
      DHCPOption mirrorOpt;
      DHCPPacket pac = new DHCPPacket();
      assertEquals(opt2, opt2.applyOption(pac));
      pac.setOptionAsInt(DHO_DHCP_LEASE_TIME, 86400);
     
      mirrorOpt = opt2.applyOption(pac);
      assertEquals(DHO_DHCP_LEASE_TIME, mirrorOpt.getCode());
      assertEquals(opt2, mirrorOpt)// not mirrored here since isMirror is false
    }
View Full Code Here

        refPacketFromHex = DHCPPacket.getPacket(refBuf, 0, refBuf.length, true);
        refPacketFromHex.setComment("foobar");
        refPacketFromHex.setAddress(InetAddress.getByName("10.11.12.13"));
        refPacketFromHex.setPort(6767);
     
      DHCPPacket packet = new DHCPPacket();
      packet.setComment("foobar");
      packet.setOp(BOOTREQUEST);
      packet.setHtype(HTYPE_ETHER);
      packet.setHlen((byte) 6);
      packet.setHops((byte) 0);
      packet.setSecs((short)0);
      packet.setXid(0x11223344);
      packet.setFlags((short) 0x8000);
      packet.setCiaddr("10.0.0.1");
      packet.setYiaddr("10.0.0.2");
      packet.setSiaddr("10.0.0.3");
      packet.setGiaddr("10.0.0.4");
      packet.setChaddr(HexUtils.hexToBytes("00112233445566778899AABBCCDDEEFF"));
      packet.setSname(STR200.substring(064));
      packet.setFile (STR200.substring(0, 128));
      packet.setDHCPMessageType(DHCPDISCOVER);
      packet.setOptionAsInetAddress(DHO_DHCP_SERVER_IDENTIFIER, "12.34.56.68");
      packet.setOptionAsInt(DHO_DHCP_LEASE_TIME, 86400);
      packet.setOptionAsInetAddress(DHO_SUBNET_MASK, "255.255.255.0");
      packet.setOptionAsInetAddress(DHO_ROUTERS, "10.0.0.254");
      InetAddress[] staticRoutes = new InetAddress[2];
      staticRoutes[0] = InetAddress.getByName("22.33.44.55");
      staticRoutes[1] = InetAddress.getByName("10.0.0.254");
      packet.setOptionAsInetAddresses(DHO_STATIC_ROUTES, staticRoutes);
      packet.setOptionAsInetAddress(DHO_NTP_SERVERS, "10.0.0.5");
      packet.setOptionAsInetAddress(DHO_WWW_SERVER, "10.0.0.6");
      packet.setPaddingWithZeroes(256);
      packet.setAddress(InetAddress.getByName("10.11.12.13"));
      packet.setPort(6767);

        refPacketFromSratch = packet;
    }
View Full Code Here

        refPacketFromSratch = packet;
    }
   
    @Before
    public void setUp() {
      pac0 = new DHCPPacket();
    }
View Full Code Here

    }


    @Test
    public void testConstrucor() throws Exception {
      DHCPPacket pac = new DHCPPacket();
     
      assertEquals("", pac.getComment());
      assertEquals(BOOTREPLY, pac.getOp());
      assertEquals(HTYPE_ETHER, pac.getHtype());
      assertEquals(6, pac.getHlen());
      assertEquals((short) 0, pac.getSecs());
      assertEquals(InetAddress.getByName("0.0.0.0"), pac.getCiaddr());
      assertEquals(InetAddress.getByName("0.0.0.0"), pac.getYiaddr());
      assertEquals(InetAddress.getByName("0.0.0.0"), pac.getSiaddr());
      assertEquals(InetAddress.getByName("0.0.0.0"), pac.getGiaddr());
      assertTrue(Arrays.equals(new byte [16], pac.getChaddr()));
      assertEquals("", pac.getSname());
      assertEquals("", pac.getFile());
      assertTrue(Arrays.equals(new byte[0], pac.getPadding()));
      assertEquals(true, pac.isDhcp());
      assertEquals(false, pac.isTruncated());
      DHCPOption[] opts = pac.getOptionsArray();
      assertNotNull(opts);
      assertEquals(0, opts.length);
     
      assertNull(pac.getAddress());
      assertEquals(0, pac.getPort());

    }
View Full Code Here

    public void testGetPacket() throws Exception {
      byte[] buf = hexToBytes(REF_PACKET);
      DatagramPacket udp = new DatagramPacket(buf, buf.length);
      udp.setAddress(InetAddress.getByName("10.11.12.13"));
      udp.setPort(6767);
      DHCPPacket pac = DHCPPacket.getPacket(udp);
      pac.setComment("foobar");

      assertEquals(refPacketFromHex, pac);
     
    }
View Full Code Here

    }
    // serialize
    @Test
    public void testSerializeLimits() {
      byte[] buf;
      DHCPPacket pac = new DHCPPacket();
      buf = pac.serialize();
      assertEquals(300, buf.length);
     
      pac.setOptionRaw(DHO_HOST_NAME, new byte[255]);
      buf = pac.serialize();
      assertEquals(498, buf.length);
     
      buf = pac.serialize(1500, 1500);
      assertEquals(1500, buf.length);
    }
View Full Code Here

      buf = pac.serialize(1500, 1500);
      assertEquals(1500, buf.length);
    }
    @Test (expected=DHCPBadPacketException.class)
    public void testSerializeOptionOver256() {
      DHCPPacket pac = new DHCPPacket();
      pac.setOptionRaw(DHO_HOST_NAME, new byte[256]);
      pac.serialize();
    }
View Full Code Here

      pac.setOptionRaw(DHO_HOST_NAME, new byte[256]);
      pac.serialize();
    }
    @Test (expected=DHCPBadPacketException.class)
    public void testSerializePacketTooBig() {
      DHCPPacket pac = new DHCPPacket();
      pac.setOptionRaw((byte)11, new byte[255]);
      pac.setOptionRaw((byte)12, new byte[255]);
      pac.setOptionRaw((byte)13, new byte[255]);
      pac.setOptionRaw((byte)14, new byte[255]);
      pac.setOptionRaw((byte)15, new byte[255]);
      pac.serialize();
    }
View Full Code Here

   
    // Limit tests for setters/getter
    @Test
    public void testSetCHAddrUnderLimit() {
      String bufs = "FFEEDDCCBBAA9988776655443322110F";
      DHCPPacket pac = new DHCPPacket();
      pac.setHlen((byte)16);
      pac.setChaddr(hexToBytes(bufs));
      assertEquals(bufs, pac.getChaddrAsHex());
      pac.setChaddr(null);
      assertEquals("00000000000000000000000000000000", pac.getChaddrAsHex());
      pac.setHlen((byte) 255);
      assertEquals("00000000000000000000000000000000", pac.getChaddrAsHex());
      pac.setChaddrHex(bufs);
      assertTrue(Arrays.equals(hexToBytes(bufs), pac.getChaddr()));
    }
View Full Code Here

TOP

Related Classes of org.dhcp4java.DHCPPacket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.