Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#clear()

The following examples show how to use org.jboss.netty.buffer.ChannelBuffer#clear() . 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: OFPortStatusTest.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
public void testWriteRead() throws Exception {
    OFPortStatus msg = (OFPortStatus) messageFactory
            .getMessage(OFType.PORT_STATUS);
    msg.setDesc(new OFPhysicalPort());
    msg.getDesc().setHardwareAddress(new byte[6]);
    msg.getDesc().setName("eth0");
    msg.setReason((byte) OFPortReason.OFPPR_ADD.ordinal());
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.PORT_STATUS, msg.getType());
    TestCase.assertEquals((byte) OFPortReason.OFPPR_ADD.ordinal(), msg
            .getReason());
    TestCase.assertNotNull(msg.getDesc());
}
 
Example 2
Source File: OFErrorTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFError msg = (OFError) messageFactory.getMessage(OFType.ERROR);
    msg.setMessageFactory(messageFactory);
    msg.setErrorType(OFErrorType.OFPET_HELLO_FAILED.getValue());
    msg.setErrorCode((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE
            .ordinal());
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFErrorType.OFPET_HELLO_FAILED.getValue(),
            msg.getErrorType());
    TestCase.assertEquals((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE
            .ordinal(), msg.getErrorType());
    TestCase.assertNull(msg.getOffendingMsg());

    msg.setOffendingMsg(new OFHello());
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFErrorType.OFPET_HELLO_FAILED.getValue(),
            msg.getErrorType());
    TestCase.assertEquals((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE
            .ordinal(), msg.getErrorType());
    TestCase.assertNotNull(msg.getOffendingMsg());
    TestCase.assertEquals(OFHello.MINIMUM_LENGTH,
            msg.getOffendingMsg().length);
}
 
Example 3
Source File: OFBarrierRequestTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFBarrierRequest msg = (OFBarrierRequest) messageFactory
            .getMessage(OFType.BARRIER_REQUEST);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.BARRIER_REQUEST, msg.getType());
}
 
Example 4
Source File: OFPortConfigTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFPortMod msg = (OFPortMod) messageFactory
            .getMessage(OFType.PORT_MOD);
    msg.setHardwareAddress(new byte[6]);
    msg.portNumber = 1;
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.PORT_MOD, msg.getType());
    TestCase.assertEquals(1, msg.getPortNumber());
}
 
Example 5
Source File: OFBarrierReplyTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFBarrierReply msg = (OFBarrierReply) messageFactory
            .getMessage(OFType.BARRIER_REPLY);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.BARRIER_REPLY, msg.getType());
}
 
Example 6
Source File: OFFlowRemovedTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFFlowRemoved msg = (OFFlowRemoved) messageFactory
            .getMessage(OFType.FLOW_REMOVED);
    msg.setMatch(new OFMatch());
    byte[] hwAddr = new byte[6];
    msg.getMatch().setDataLayerDestination(hwAddr);
    msg.getMatch().setDataLayerSource(hwAddr);
    msg.setReason(OFFlowRemovedReason.OFPRR_DELETE);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.FLOW_REMOVED, msg.getType());
    TestCase.assertEquals(OFFlowRemovedReason.OFPRR_DELETE, msg.getReason());
}
 
Example 7
Source File: OFSetConfigTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFGetConfigReply msg = (OFGetConfigReply) messageFactory
            .getMessage(OFType.GET_CONFIG_REPLY);
    msg.setFlags((short) 1);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.GET_CONFIG_REPLY, msg.getType());
    TestCase.assertEquals((short)1, msg.getFlags());
}
 
Example 8
Source File: OFVendorTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFVendor msg = makeVendorMessage(1);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(1, msg.getVendor());
}
 
Example 9
Source File: OFVendorTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testVendorData() throws Exception {
    OFVendor msg = makeVendorMessage(ACME_VENDOR_ID);
    OFVendorData vendorData = new AcmeVendorData1((short)11, (short)22);
    msg.setVendorData(vendorData);
    msg.setLengthU(OFVendor.MINIMUM_LENGTH + vendorData.getLength());
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    assertEquals(ACME_VENDOR_ID, msg.getVendor());
    AcmeVendorData1 vendorData1 = (AcmeVendorData1) msg.getVendorData();
    assertEquals(11, vendorData1.getFlags());
    assertEquals(22, vendorData1.getValue());
    
    vendorData = new AcmeVendorData2(33, 44);
    msg.setVendorData(vendorData);
    msg.setLengthU(OFVendor.MINIMUM_LENGTH + vendorData.getLength());
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    assertEquals(ACME_VENDOR_ID, msg.getVendor());
    AcmeVendorData2 vendorData2 = (AcmeVendorData2) msg.getVendorData();
    assertEquals(33, vendorData2.getType());
    assertEquals(44, vendorData2.getSubtype());
    
    final int DUMMY_VENDOR_ID = 55;
    msg.setVendor(DUMMY_VENDOR_ID);
    byte[] genericVendorDataBytes = new byte[] {0x55, 0x66};
    vendorData = new OFByteArrayVendorData(genericVendorDataBytes);
    msg.setVendorData(vendorData);
    msg.setLengthU(OFVendor.MINIMUM_LENGTH + vendorData.getLength());
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    assertEquals(DUMMY_VENDOR_ID, msg.getVendor());
    OFByteArrayVendorData genericVendorData = (OFByteArrayVendorData) msg.getVendorData();
    assertTrue(Arrays.equals(genericVendorDataBytes, genericVendorData.getBytes()));
}
 
Example 10
Source File: OFFeaturesReplyTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFFeaturesReply ofr = (OFFeaturesReply) messageFactory
            .getMessage(OFType.FEATURES_REPLY);
    List<OFPhysicalPort> ports = new ArrayList<OFPhysicalPort>();
    OFPhysicalPort port = new OFPhysicalPort();
    port.setHardwareAddress(new byte[6]);
    port.setName("eth0");
    ports.add(port);
    ofr.setPorts(ports);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    ofr.writeTo(bb);
    ofr.readFrom(bb);
    TestCase.assertEquals(1, ofr.getPorts().size());
    TestCase.assertEquals("eth0", ofr.getPorts().get(0).getName());

    // test a 15 character name
    ofr.getPorts().get(0).setName("012345678901234");
    bb.clear();
    ofr.writeTo(bb);
    ofr.readFrom(bb);
    TestCase.assertEquals("012345678901234", ofr.getPorts().get(0).getName());

    // test a 16 character name getting truncated
    ofr.getPorts().get(0).setName("0123456789012345");
    bb.clear();
    ofr.writeTo(bb);
    ofr.readFrom(bb);
    TestCase.assertEquals("012345678901234", ofr.getPorts().get(0).getName());
}
 
Example 11
Source File: OFGetConfigRequestTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFGetConfigRequest msg = (OFGetConfigRequest) messageFactory
            .getMessage(OFType.GET_CONFIG_REQUEST);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.GET_CONFIG_REQUEST, msg.getType());
}
 
Example 12
Source File: OFGetConfigReplyTest.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void testWriteRead() throws Exception {
    OFSetConfig msg = (OFSetConfig) messageFactory
            .getMessage(OFType.SET_CONFIG);
    msg.setFlags((short) 1);
    ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
    bb.clear();
    msg.writeTo(bb);
    msg.readFrom(bb);
    TestCase.assertEquals(OFType.SET_CONFIG, msg.getType());
    TestCase.assertEquals((short)1, msg.getFlags());
}