Examples of BasicFactory


Examples of org.openflow.protocol.factory.BasicFactory

import org.openflow.util.U16;

public class BasicFactoryTest extends TestCase {

    public void testCreateAndParse() throws MessageParseException {
        BasicFactory factory = BasicFactory.getInstance();
        OFMessage m = factory.getMessage(OFType.HELLO);
        m.setVersion((byte) 1);
        m.setType(OFType.ECHO_REQUEST);
        m.setLength(U16.t(8));
        m.setXid(0xdeadbeef);
        ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
        ChannelBuffer bb2 = ChannelBuffers.dynamicBuffer();
        m.writeTo(bb);
        bb2.writeBytes(bb, bb.readableBytes()-1);
        TestCase.assertNull(factory.parseMessage(bb2));
        bb2.writeByte(bb.readByte());
        List<OFMessage> message = factory.parseMessage(bb2);
        TestCase.assertNotNull(message);
        TestCase.assertEquals(message.size(), 1);
        TestCase.assertTrue(message.get(0).getType() == OFType.ECHO_REQUEST);
    }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

        TestCase.assertEquals(message.size(), 1);
        TestCase.assertTrue(message.get(0).getType() == OFType.ECHO_REQUEST);
    }

    public void testInvalidMsgParse() throws MessageParseException {
        BasicFactory factory = BasicFactory.getInstance();
        OFMessage m = factory.getMessage(OFType.HELLO);
        m.setVersion((byte) 1);
        m.setType(OFType.ECHO_REQUEST);
        m.setLength(U16.t(16));
        m.setXid(0xdeadbeef);
        ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
        m.writeTo(bb);
        List<OFMessage> message = factory.parseMessage(bb);
        TestCase.assertNull(message);
    }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

        List<OFMessage> message = factory.parseMessage(bb);
        TestCase.assertNull(message);
    }

    public void testCurrouptedMsgParse() throws MessageParseException {
        BasicFactory factory = BasicFactory.getInstance();
        OFMessage m = factory.getMessage(OFType.HELLO);
        m.setVersion((byte) 1);
        m.setType(OFType.ERROR);
        m.setLength(U16.t(8));
        m.setXid(0xdeadbeef);
        ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
        m.writeTo(bb);
        try {
                factory.parseMessage(bb);
        }
        catch(Exception e) {
            TestCase.assertEquals(MessageParseException.class, e.getClass());
        }
    }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

            TestCase.assertEquals(MessageParseException.class, e.getClass());
        }
    }

    public void testCustomVendorAction() throws MessageParseException {
        BasicFactory factory = BasicFactory.getInstance();
        OFVendorActionRegistry.getInstance().register(
                MockVendorAction.VENDOR_ID, new MockVendorActionFactory());


        byte[] deadBeefMessage = {
            (byte) 0xff, (byte) 0xff,          // action vendor
            0x00, 0x10,                        // length
            (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte)0xef,            // deadbeaf
            0x01, 0x02, 0x03, 0x04,
            0x05, 0x06, 0x07, 0x08               // pad
        };

        ChannelBuffer buf = ChannelBuffers.copiedBuffer(deadBeefMessage);

        List<OFAction> actions = factory.parseActions(buf,deadBeefMessage.length);
        assertEquals(1, actions.size());
        OFAction ofAction = actions.get(0);
        assertTrue("Action should be MockVendorAction, but is "+ofAction.getClass(), ofAction instanceof MockVendorAction);
        assertArrayEquals( new byte[]  { 1,2,3,4,5,6,7,8}, ((MockVendorAction)ofAction).getMockData());
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

                (byte) 0x7e, (byte) 0xe7, (byte) 0xbe, (byte)0xef,            // deadbeaf
                0x01, 0x02, 0x03, 0x04,
                0x05, 0x06, 0x07, 0x08               // pad
            };

        BasicFactory factory = BasicFactory.getInstance();
        OFVendorActionRegistry.getInstance().register(
                MockVendorAction.VENDOR_ID, new MockVendorActionFactory());

        ChannelBuffer buf = ChannelBuffers.copiedBuffer(nonDeadBeefMessage);

        List<OFAction> actions = factory.parseActions(buf,nonDeadBeefMessage.length);
        assertEquals(1, actions.size());
        OFAction ofAction = actions.get(0);
        assertTrue("Action should be OFActionVendorGeneric, but is "+ofAction.getClass(), ofAction instanceof OFActionVendorGeneric);
    }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

        SocketChannel client = SocketChannel.open(
                new InetSocketAddress("localhost",
                        serverSC.socket().getLocalPort())
                );
        SocketChannel server = serverSC.accept();
        OFMessageAsyncStream clientStream = new OFMessageAsyncStream(client, new BasicFactory());
        OFMessageAsyncStream serverStream = new OFMessageAsyncStream(server, new BasicFactory());
       
        clientStream.write(h);
        while(clientStream.needsFlush()) {
            clientStream.flush();
        }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

        bb.clear();
        reply.writeTo(bb);
        bb.flip();

        OFQueueConfigReply reply2 = new OFQueueConfigReply();
        reply2.setQueuePropertyFactory(new BasicFactory());
        reply2.readFrom(bb);
        TestCase.assertEquals(reply, reply2);
        TestCase.assertEquals(1, reply2.getQueues().size());
        TestCase.assertEquals(1, reply2.getQueues().get(0).getProperties().size());
        TestCase.assertTrue(reply2.getQueues().get(0).getProperties().get(0) instanceof OFQueuePropertyMinRate);
        TestCase.assertEquals(OFQueuePropertyType.MIN_RATE, reply2.getQueues().get(0).getProperties().get(0).getType());

        reply.getQueues().add(queue.clone());
        reply.setLengthU(reply.getLengthU() + queue.getLength());
        bb.clear();
        reply.writeTo(bb);
        bb.flip();
        reply2 = new OFQueueConfigReply();
        reply2.setQueuePropertyFactory(new BasicFactory());
        reply2.readFrom(bb);
        TestCase.assertEquals(reply, reply2);
        TestCase.assertEquals(2, reply2.getQueues().size());

        queue.getProperties().add(new OFQueuePropertyMinRate().setRate((short) 2));
        queue.setLength((short) (queue.getLength() + OFQueuePropertyMinRate.MINIMUM_LENGTH));
        reply.setLengthU(reply.getLengthU() + OFQueuePropertyMinRate.MINIMUM_LENGTH);
        bb.clear();
        reply.writeTo(bb);
        bb.flip();
        reply2 = new OFQueueConfigReply();
        reply2.setQueuePropertyFactory(new BasicFactory());
        reply2.readFrom(bb);
        TestCase.assertEquals(reply, reply2);
        TestCase.assertEquals(2, reply2.getQueues().size());
        TestCase.assertEquals(2, reply2.getQueues().get(0).getProperties().size());
    }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

    public OFMessageFactory messageFactory;
   
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        messageFactory = new BasicFactory();
    }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

        threadCount = 1;
        listenSelectLoop = new SelectLoop(this);
        // register this connection for accepting
        listenSelectLoop.register(listenSock, SelectionKey.OP_ACCEPT, listenSock);

        this.factory = new BasicFactory();
    }
View Full Code Here

Examples of org.openflow.protocol.factory.BasicFactory

                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00 };
        OFMessageFactory factory = new BasicFactory();
        ByteBuffer oferrorBuf = ByteBuffer.wrap(oferrorRaw);
        List<OFMessage> msgs = factory.parseMessages(oferrorBuf,
                oferrorRaw.length);
        TestCase.assertEquals(1, msgs.size());
        OFMessage msg = msgs.get(0);
        TestCase.assertEquals(76, msg.getLengthU());
        ByteBuffer out = ByteBuffer.allocate(1024);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.