97ff59bd075260d9d6e738e6073d8c3548e496be
[controller.git] / third-party / openflowj / src / test / java / org / openflow / protocol / OFFeaturesReplyTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.openflow.protocol;
11
12
13 import java.nio.ByteBuffer;
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import junit.framework.TestCase;
18
19 import org.openflow.util.OFTestCase;
20
21
22 public class OFFeaturesReplyTest extends OFTestCase {
23     public void testWriteRead() throws Exception {
24         OFFeaturesReply ofr = (OFFeaturesReply) messageFactory
25                 .getMessage(OFType.FEATURES_REPLY);
26         List<OFPhysicalPort> ports = new ArrayList<OFPhysicalPort>();
27         OFPhysicalPort port = new OFPhysicalPort();
28         port.setHardwareAddress(new byte[6]);
29         port.setName("eth0");
30         ports.add(port);
31         ofr.setPorts(ports);
32         ByteBuffer bb = ByteBuffer.allocate(1024);
33         bb.clear();
34         ofr.writeTo(bb);
35         bb.flip();
36         ofr.readFrom(bb);
37         TestCase.assertEquals(1, ofr.getPorts().size());
38         TestCase.assertEquals("eth0", ofr.getPorts().get(0).getName());
39
40         // test a 15 character name
41         ofr.getPorts().get(0).setName("012345678901234");
42         bb.clear();
43         ofr.writeTo(bb);
44         bb.flip();
45         ofr.readFrom(bb);
46         TestCase.assertEquals("012345678901234", ofr.getPorts().get(0).getName());
47
48         // test a 16 character name getting truncated
49         ofr.getPorts().get(0).setName("0123456789012345");
50         bb.clear();
51         ofr.writeTo(bb);
52         bb.flip();
53         ofr.readFrom(bb);
54         TestCase.assertEquals("012345678901234", ofr.getPorts().get(0).getName());
55     }
56 }