Example usage for io.netty.buffer Unpooled buffer

List of usage examples for io.netty.buffer Unpooled buffer

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled buffer.

Prototype

public static ByteBuf buffer() 

Source Link

Document

Creates a new big-endian Java heap buffer with reasonably small initial capacity, which expands its capacity boundlessly on demand.

Usage

From source file:TestDescriptor.java

License:Open Source License

@Test
public void ACDescriptorTest() {
    StackTraceElement bTop = Thread.currentThread().getStackTrace()[1];
    ODLCapwapMessage msg = null;//  ww w.  ja v  a2  s.co m
    DiscoveryType discoveryType = null;
    ACDescriptor acDescriptor = null;
    ACName acname = null;

    msg = new ODLCapwapMessage();

    //create  Discovery Type
    discoveryType = new DiscoveryType();
    discoveryType.setDhcp();
    msg.ctrlMsg.addMessageElement(discoveryType);

    //create AcDescriptor element
    acDescriptor = new ACDescriptor();
    acDescriptor.setStations(2).setActiveWtps(2).setLimit(12).setMaxWtps(3).setSecuritySbit().setRmac((byte) 2)
            .setDtlsPolicyDbit();
    //Now create Information Sub Element
    ACInformationSubElement e = new ACInformationSubElement(64);
    byte[] dummy = new byte[64];
    e.setAcInfoVendorId(12);
    e.setAcInfoType(35);
    e.setAcInfoData(dummy);

    acDescriptor.addAcInformationSubElem(e);

    ACInformationSubElement e1 = new ACInformationSubElement(128);
    byte[] dummy1 = new byte[128];
    e1.setAcInfoVendorId(102);
    e1.setAcInfoType(3);
    e1.setAcInfoData(dummy1);
    acDescriptor.addAcInformationSubElem(e1);

    //Add message element to Capwap Message
    msg.ctrlMsg.addMessageElement(acDescriptor);

    msg.ctrlMsg.setMsgType(ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST);
    msg.ctrlMsg.setSeqNo((short) 1);

    acname = new ACName();
    acname.setName(new byte[] { 'T', 'h', 'i', 's', ' ', 'i', 's', ',', 'm', 'y', 'n', 'a', 'm', 'e' });
    //acname.setName("k1");
    acname.setLength(2);
    msg.ctrlMsg.addMessageElement(acname);

    ByteBuf buf = Unpooled.buffer();
    msg.header.encodeHeader(buf);
    msg.ctrlMsg.encode(buf);

    ODLCapwapMessage n = null;
    n = ODLCapwapMessageFactory.decodeFromByteArray(buf);
    //boolean m = false;
    //Assert.assertEquals(msg,m);

    sender(buf);
    Assert.assertEquals(msg, n);

}

From source file:TestDescriptor.java

License:Open Source License

@Test
public void WtpReootStatisticsTester() {
    StackTraceElement bTop = Thread.currentThread().getStackTrace()[1];
    ODLCapwapMessage msg = null;//ww  w.j  a  v  a  2s.  c  om
    ODLCapwapMessage n = null;

    WTPRebootStatistics rebootStatistics = new WTPRebootStatistics();

    msg = new ODLCapwapMessage();

    //create  Discovery Type
    rebootStatistics.setLastFailureType((short) 1);
    rebootStatistics.setSoftwareFailure(2);
    rebootStatistics.setAcInitiated(3);
    rebootStatistics.setLinkFailure(4);
    rebootStatistics.setUnKnownFailure(5);
    rebootStatistics.setRebootCount(6);
    rebootStatistics.setOtherFailure(7);
    rebootStatistics.setHwFailure(8);

    msg.ctrlMsg.addMessageElement(rebootStatistics);

    msg.ctrlMsg.setMsgType(ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST);
    msg.ctrlMsg.setSeqNo((short) 1);
    ByteBuf buf = Unpooled.buffer();
    msg.header.encodeHeader(buf);
    msg.ctrlMsg.encode(buf);
    n = ODLCapwapMessageFactory.decodeFromByteArray(buf);
    sender(buf);
    Assert.assertEquals(msg, n);
    //LOG.info("Decoding  SUCCESS for {}:", getFunctionName(bTop));
    //encodeDecodeTester(msg,n);

}

From source file:TestDescriptor.java

License:Open Source License

@Test
public void ECNTest() {
    StackTraceElement bTop = Thread.currentThread().getStackTrace()[1];
    ODLCapwapMessage msg = null;/*from  w  ww  . j a  va2 s  . c o m*/
    ODLCapwapMessage n = null;

    ECNSupport ecnSupport = new ECNSupport();

    msg = new ODLCapwapMessage();

    //create  Discovery Type
    ecnSupport.setEcn((byte) 2);
    msg.ctrlMsg.addMessageElement(ecnSupport);
    msg.ctrlMsg.setMsgType(ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST);
    msg.ctrlMsg.setSeqNo((short) 1);
    ByteBuf buf = Unpooled.buffer();
    msg.header.encodeHeader(buf);
    msg.ctrlMsg.encode(buf);
    n = ODLCapwapMessageFactory.decodeFromByteArray(buf);
    sender(buf);
    Assert.assertEquals(msg, n);
}

From source file:TestDescriptor.java

License:Open Source License

@Test
public void DiscoveryDescriptorTest() {
    StackTraceElement bTop = Thread.currentThread().getStackTrace()[1];
    ODLCapwapMessage msg = null;//from   ww w. j a  v a2s . com
    ODLCapwapMessage n = null;
    DiscoveryType discoveryType = null;
    ACDescriptor acDescriptor = null;

    msg = new ODLCapwapMessage();

    //create  Discovery Type
    discoveryType = new DiscoveryType();
    discoveryType.setDhcp();
    msg.ctrlMsg.addMessageElement(discoveryType);
    msg.ctrlMsg.setMsgType(ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST);
    msg.ctrlMsg.setSeqNo((short) 1);
    ByteBuf buf = Unpooled.buffer();
    msg.header.encodeHeader(buf);
    msg.ctrlMsg.encode(buf);
    n = ODLCapwapMessageFactory.decodeFromByteArray(buf);
    sender(buf);
    Assert.assertEquals(msg, n);

}

From source file:TestDescriptor.java

License:Open Source License

@Test
public void WtpMacTypeDescriptorTest() {
    StackTraceElement bTop = Thread.currentThread().getStackTrace()[1];
    ODLCapwapMessage msg = null;//from  www  .j a  va  2  s. c  o  m
    ODLCapwapMessage n = null;
    WtpMacTypeMsgElem macType = null;
    msg = new ODLCapwapMessage();

    //create  Discovery Type
    macType = new WtpMacTypeMsgElem();
    macType.setTypeLocal();
    msg.ctrlMsg.addMessageElement(macType);

    msg.ctrlMsg.setMsgType(ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST);
    msg.ctrlMsg.setSeqNo((short) 1);
    ByteBuf buf = Unpooled.buffer();
    msg.header.encodeHeader(buf);
    msg.ctrlMsg.encode(buf);
    n = ODLCapwapMessageFactory.decodeFromByteArray(buf);
    sender(buf);
    Assert.assertEquals(msg, n);
}

From source file:TestDescriptor.java

License:Open Source License

@Test
public void maxLenTester() {
    StackTraceElement bTop = Thread.currentThread().getStackTrace()[1];

    ODLCapwapMessage msg = null;/*from w  w  w . j ava2s .c  o m*/
    ODLCapwapMessage n = null;

    msg = new ODLCapwapMessage();

    MaxMsgLength l = new MaxMsgLength();
    l.setMaxLength(32000);

    msg.ctrlMsg.addMessageElement(l);

    msg.ctrlMsg.setMsgType(ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST);
    msg.ctrlMsg.setSeqNo((short) 1);
    ByteBuf buf = Unpooled.buffer();
    msg.header.encodeHeader(buf);
    msg.ctrlMsg.encode(buf);
    n = ODLCapwapMessageFactory.decodeFromByteArray(buf);
    sender(buf);
    Assert.assertEquals(msg, n);
}

From source file:WtpTestClient.java

License:Open Source License

public static void main(String args[]) {

    WtpTestClient tester = new WtpTestClient();
    ODLCapwapMessage msg = null;/*from  w  w  w . j  a  va  2  s .c o m*/
    int input = 0;
    Scanner sc = new Scanner(System.in);

    while (input != -1) {
        ByteBuf buf = Unpooled.buffer();
        System.out.printf("\nEnter the CAPWAP Message Number , enter \"-1\" to exit\n");
        input = sc.nextInt();
        if (input == -1)
            break;
        System.out.printf("\nInput Choice %d\n", input);
        switch (input) {
        case ODLCapwapConsts.ODL_CAPWAP_DISCOVERY_REQUEST:
            msg = CapwapMessageCreator.createRequest(input); //later each of the functions needs to be changd with custom methods
            break;
        case ODLCapwapConsts.ODL_CAPWAP_PRIMARY_DISCOVERY_REQUEST:
            msg = tester.createDiscoveryRequest(input);
            break;
        case ODLCapwapConsts.ODL_CAPWAP_JOIN_REQUEST:
            msg = CapwapMessageCreator.createRequest(input);
            break;
        case ODLCapwapConsts.ODL_CAPWAP_ECHO_REQUEST:
            msg = CapwapMessageCreator.createRequest(input);
            break;
        case ODLCapwapConsts.ODL_CAPWAP_CONFIG_STATUS_REQUEST:
            msg = CapwapMessageCreator.createRequest(input);
            break;
        case ODLCapwapConsts.ODL_CAPWAP_CHANGE_STATE_EVENT_REQUEST:
            msg = CapwapMessageCreator.createRequest(input);
            break;
        case ODLCapwapConsts.ODL_CAPWAP_CLEAR_CONFIG_REQUEST:
            msg = CapwapMessageCreator.createRequest(input);
            break;
        case ODLCapwapConsts.ODL_CAPWAP_IMAGE_DATA_REQUEST:
            msg = CapwapMessageCreator.createRequest(input);
            break;
        case ODLCapwapConsts.ODL_CAPWAP_WTP_EVENT_REQUEST:
            msg = CapwapMessageCreator.createRequest(input);
            break;

        default:

        }//end of switch(input)
        msg.header.encodeHeader(buf);
        msg.ctrlMsg.encode(buf);
        tester.sender(buf);

        //encode the message and send the message to AC
    } //end of while

}

From source file:UdpClient.java

License:Open Source License

public static void main(String args[]) {

    byte[] buf = new byte[256];
    DatagramSocket socket = null;
    try {//from   www .ja v a2  s  .  c  o  m
        socket = new DatagramSocket();
    } catch (SocketException e) {
        e.printStackTrace();
    }
    InetAddress address = null;
    try {
        address = InetAddress.getLoopbackAddress();
        System.out.println(address);
    } catch (Exception e) {
        e.printStackTrace();
    }
    buf = "hello".getBytes();
    ByteBuf nett_buf = Unpooled.buffer();

    InetSocketAddress socketAddress = new InetSocketAddress(address, 5246);
    Scanner sc = new Scanner(System.in);
    {
        System.out.println("\nEnter Capwap Message ID");
        //int longIn = 4294967294;
        int longIn = 0XFFFFFFFE;
        nett_buf.writeInt(longIn);
        buf = nett_buf.array();

        DatagramPacket packet = new DatagramPacket(buf, nett_buf.writerIndex(), address, 5246);
        try {
            socket.send(packet);
            System.out.printf("\nSending Capwap Message %x ", longIn);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test(dataProvider = "getAddressAndQuantity")
public void testReadCoilsRequest(int address, int quantity) {
    ReadCoilsRequest request = new ReadCoilsRequest(address, quantity);

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    ReadCoilsRequest decoded = (ReadCoilsRequest) decoder.decode(encoded);

    assertEquals(request.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getQuantity(), decoded.getQuantity());
}

From source file:ModbusRequestSerializationTest.java

License:Apache License

@Test(dataProvider = "getAddressAndQuantity")
public void testReadDiscreteInputsRequest(int address, int quantity) {
    ReadDiscreteInputsRequest request = new ReadDiscreteInputsRequest(address, quantity);

    ByteBuf encoded = encoder.encode(request, Unpooled.buffer());
    ReadDiscreteInputsRequest decoded = (ReadDiscreteInputsRequest) decoder.decode(encoded);

    assertEquals(request.getFunctionCode(), decoded.getFunctionCode());
    assertEquals(request.getAddress(), decoded.getAddress());
    assertEquals(request.getQuantity(), decoded.getQuantity());
}