3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.openflow.io;
12 import org.openflow.protocol.*;
13 import org.openflow.protocol.factory.BasicFactory;
16 import java.nio.channels.*;
17 import java.net.InetSocketAddress;
19 import org.junit.Assert;
21 import org.junit.Test;
25 * @author Rob Sherwood (rob.sherwood@stanford.edu)
28 public class OFMessageAsyncStreamTest {
30 public void testMarshalling() throws Exception {
31 OFMessage h = new OFHello();
33 ServerSocketChannel serverSC = ServerSocketChannel.open();
34 serverSC.socket().bind(new java.net.InetSocketAddress(0));
35 serverSC.configureBlocking(false);
37 SocketChannel client = SocketChannel.open(
38 new InetSocketAddress("localhost",
39 serverSC.socket().getLocalPort())
41 SocketChannel server = serverSC.accept();
42 OFMessageAsyncStream clientStream = new OFMessageAsyncStream(client, new BasicFactory());
43 OFMessageAsyncStream serverStream = new OFMessageAsyncStream(server, new BasicFactory());
45 clientStream.write(h);
46 while(clientStream.needsFlush()) {
49 List<OFMessage> l = serverStream.read();
50 Assert.assertEquals(l.size(), 1);
51 OFMessage m = l.get(0);
52 Assert.assertEquals(m.getLength(),h.getLength());
53 Assert.assertEquals(m.getVersion(), h.getVersion());
54 Assert.assertEquals(m.getType(), h.getType());
55 Assert.assertEquals(m.getType(), h.getType());