Merge "Updated registration of Binding Aware notification listeners."
[controller.git] / third-party / openflowj / src / test / java / org / openflow / protocol / OFStatisticsRequestTest.java
1 package org.openflow.protocol;
2
3 import java.nio.ByteBuffer;
4 import java.util.List;
5
6 import junit.framework.TestCase;
7
8 import org.openflow.protocol.factory.BasicFactory;
9 import org.openflow.protocol.factory.OFMessageFactory;
10 import org.openflow.protocol.statistics.OFFlowStatisticsRequest;
11 import org.openflow.protocol.statistics.OFStatisticsType;
12 import org.openflow.protocol.statistics.OFVendorStatistics;
13 import org.openflow.util.OFTestCase;
14
15 public class OFStatisticsRequestTest extends OFTestCase {
16     public void testOFFlowStatisticsRequest() throws Exception {
17         byte[] packet = new byte[] { 0x01, 0x10, 0x00, 0x38, 0x00, 0x00, 0x00,
18                 0x16, 0x00, 0x01, 0x00, 0x00, (byte) 0xff, (byte) 0xff,
19                 (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
22                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23                 (byte) 0xff, 0x00, (byte) 0xff, (byte) 0xff };
24
25         OFMessageFactory factory = new BasicFactory();
26         ByteBuffer packetBuf = ByteBuffer.wrap(packet);
27         List<OFMessage> msgs = factory.parseMessages(packetBuf, packet.length);
28         TestCase.assertEquals(1, msgs.size());
29         TestCase.assertTrue(msgs.get(0) instanceof OFStatisticsRequest);
30         OFStatisticsRequest sr = (OFStatisticsRequest) msgs.get(0);
31         TestCase.assertEquals(OFStatisticsType.FLOW, sr.getStatisticType());
32         TestCase.assertEquals(1, sr.getStatistics().size());
33         TestCase.assertTrue(sr.getStatistics().get(0) instanceof OFFlowStatisticsRequest);
34     }
35
36     public void testOFStatisticsRequestVendor() throws Exception {
37         byte[] packet = new byte[] { 0x01, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00,
38                 0x63, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
39                 0x4c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40                 0x01, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x20,
41                 (byte) 0xe0, 0x00, 0x11, 0x00, 0x0c, 0x29, (byte) 0xc5,
42                 (byte) 0x95, 0x57, 0x02, 0x25, 0x5c, (byte) 0xca, 0x00, 0x02,
43                 (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
44                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x50, 0x04,
45                 0x00, 0x00, 0x00, 0x00, (byte) 0xff, 0x00, 0x00, 0x00,
46                 (byte) 0xff, (byte) 0xff, 0x4e, 0x20 };
47
48         OFMessageFactory factory = new BasicFactory();
49         ByteBuffer packetBuf = ByteBuffer.wrap(packet);
50         List<OFMessage> msgs = factory.parseMessages(packetBuf, packet.length);
51         TestCase.assertEquals(1, msgs.size());
52         TestCase.assertTrue(msgs.get(0) instanceof OFStatisticsRequest);
53         OFStatisticsRequest sr = (OFStatisticsRequest) msgs.get(0);
54         TestCase.assertEquals(OFStatisticsType.VENDOR, sr.getStatisticType());
55         TestCase.assertEquals(1, sr.getStatistics().size());
56         TestCase.assertTrue(sr.getStatistics().get(0) instanceof OFVendorStatistics);
57         TestCase.assertEquals(68, ((OFVendorStatistics)sr.getStatistics().get(0)).getLength());
58     }
59 }