Package org.xbill.DNS

Examples of org.xbill.DNS.Record


        ByteBuffer buf = ByteBuffer.allocate(100);
        channel.read(buf);

        Message message = new Message(buf.array());
        Record answer = message.getSectionArray(Section.ANSWER)[0];
        Assert.assertEquals(Type.A, answer.getType());
        String addr = ((ARecord)answer).getAddress().getHostAddress();
        Assert.assertEquals("1.2.3.4", addr);

        query =  Message.newQuery(
                Record.newRecord(new Name("foo.example.com."), Type.AAAA, DClass.IN));
        channel.write(ByteBuffer.wrap(query.toWire()));

        Thread.sleep(10);

        buf.clear();
        channel.read(buf);

        message = new Message(buf.array());
        answer = message.getSectionArray(Section.ANSWER)[0];
        Assert.assertEquals(Type.AAAA, answer.getType());
        addr = ((AAAARecord)answer).getAddress().getHostAddress();
        Assert.assertEquals("2002:53fe:a000:0:0:0:0:1", addr);
    }
View Full Code Here


        };

        TestingConfiguration conf = new TestingConfiguration("bar", "example.com.", 12345);

        Protocol protocol = new BinaryBackendProtocol();
        Record result = protocol.decode(ipv4message, conf);
        ARecord rec = (ARecord) result;
        Assert.assertEquals("foo.example.com.", rec.getName().toString());
        Assert.assertEquals("192.168.0.1", rec.getAddress().getHostAddress());
        Assert.assertEquals(12345, rec.getTTL());
    }
View Full Code Here

        };

        TestingConfiguration conf = new TestingConfiguration("bar", "example.com.", 12345);

        Protocol protocol = new BinaryBackendProtocol();
        Record result = protocol.decode(ipv6message, conf);
        AAAARecord rec = (AAAARecord) result;
        Assert.assertEquals("foo.example.com.", rec.getName().toString());
        Assert.assertEquals("2002:53fe:52a1:7:224:1dff:fe7d:6bef", rec.getAddress().getHostAddress());
        Assert.assertEquals(12345, rec.getTTL());
    }
View Full Code Here

    public void encodeRequest() throws Exception {
        TestingConfiguration conf = new TestingConfiguration("bar", "example.com.", 12345);

        Protocol protocol = new JSONBackendProtocol();

        Record rec = Record.newRecord(new Name("foo.example.com."), Type.A, DClass.IN);
        byte[] data = protocol.encode(rec, conf);

        String expectedStr = "{ \"type\": \"Request\", \"moniker\": \"bar\", \"name\": \"foo\" }";
        Map<String, Object> expected = mapper.readValue(expectedStr, new TypeReference<HashMap<String, Object>>(){});
        Map<String, Object> actual = mapper.readValue(data, new TypeReference<HashMap<String, Object>>(){});
View Full Code Here

                "\"address\": \"192.168.0.1\", " +
                "\"family\": \"ipv4\", " +
                "\"moniker\": \"bar\" }";

        Protocol protocol = new JSONBackendProtocol();
        Record result = protocol.decode(update.getBytes(), conf);

        ARecord rec = (ARecord) result;
        Assert.assertEquals("foo.example.com.", rec.getName().toString());
        Assert.assertEquals("192.168.0.1", rec.getAddress().getHostAddress());
        Assert.assertEquals(12345, rec.getTTL());
View Full Code Here

                "\"address\": \"2002:53fe:52a1:7:224:1dff:fe7d:6bef\", " +
                "\"family\": \"ipv6\", " +
                "\"moniker\": \"bar\" }";

        Protocol protocol = new JSONBackendProtocol();
        Record result = protocol.decode(update.getBytes(), conf);

        AAAARecord rec = (AAAARecord) result;
        Assert.assertEquals("foo.example.com.", rec.getName().toString());
        Assert.assertEquals("2002:53fe:52a1:7:224:1dff:fe7d:6bef", rec.getAddress().getHostAddress());
        Assert.assertEquals(12345, rec.getTTL());
View Full Code Here

    public void firstSerialisationPerformance() throws Exception {
        TestingConfiguration conf = new TestingConfiguration("bar", "example.com.", 12345);

        Protocol protocol = new JSONBackendProtocol();

        Record rec = Record.newRecord(new Name("foo.example.com."), Type.A, DClass.IN);
        long start = System.currentTimeMillis();
        byte[] data = protocol.encode(rec, conf);
        long consumed = System.currentTimeMillis() - start;
        System.out.println(consumed);
        Assert.assertTrue(consumed < 25);
View Full Code Here

        SimpleBackend backend = new SimpleBackend("A", arec);
        backend.setConfiguration(conf);
        backend.setCache(cache);

        Record question = Record.newRecord(new Name("foo.example.com."), Type.A, DClass.IN);
        backend.notify(question);

        Assert.assertNotNull(cache.get("A:foo.example.com."));

        Thread.sleep(1010);
View Full Code Here

        } catch (IllegalStateException e) { }
    }

    @Test
    public void interpretUDPQuery() throws Exception {
        Record rec = Record.newRecord(Name.fromString("foo.example.com."), Type.A, DClass.IN);
        Message query = Message.newQuery(rec);

        byte[] qdata = query.toWire();
        DatagramPacket packet = new DatagramPacket(qdata, qdata.length,
                InetAddress.getLoopbackAddress(), 53);
View Full Code Here

            throw new ProtocolCodingException(e);
        }

        int ttl = configuration.getTtl(update.moniker);

        Record record;
        if("ipv4".equals(update.family)) {
            record =  new ARecord(qualified, DClass.IN, ttl, address);
        } else if ("ipv6".equals(update.family)) {
            record = new AAAARecord(qualified, DClass.IN, ttl, address);
        } else {
View Full Code Here

TOP

Related Classes of org.xbill.DNS.Record

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.