Package org.openflow.protocol

Source Code of org.openflow.protocol.BasicFactoryTest

package org.openflow.protocol;

import java.nio.ByteBuffer;
import java.util.List;

import org.openflow.protocol.factory.BasicFactory;
import org.openflow.util.U16;

import junit.framework.TestCase;



public class BasicFactoryTest extends TestCase {
    public void testCreateAndParse() {
        BasicFactory factory = new BasicFactory();
        OFMessage m = factory.getMessage(OFType.HELLO);
        m.setVersion((byte) 1);
        m.setType(OFType.ECHO_REQUEST);
        m.setLength(U16.t(8));
        m.setXid(0xdeadbeef);
        ByteBuffer bb = ByteBuffer.allocate(1024);
        m.writeTo(bb);
        bb.flip();
        bb.limit(bb.limit()-1);
        TestCase.assertEquals(0, factory.parseMessages(bb).size());
        bb.limit(bb.limit()+1);
        List<OFMessage> messages = factory.parseMessages(bb);
        TestCase.assertEquals(1, messages.size());
        TestCase.assertTrue(messages.get(0).getType() == OFType.ECHO_REQUEST);
    }
}
TOP

Related Classes of org.openflow.protocol.BasicFactoryTest

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.