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