Performacne improvements via adding a netty-based openflowj and openflow plugin;...
[controller.git] / third-party / openflowj_netty / src / test / java / org / openflow / protocol / OFStatisticsRequestTest.java
1 /**
2 *    Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3 *    University
4
5 *    Licensed under the Apache License, Version 2.0 (the "License"); you may
6 *    not use this file except in compliance with the License. You may obtain
7 *    a copy of the License at
8 *
9 *         http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *    Unless required by applicable law or agreed to in writing, software
12 *    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 *    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 *    License for the specific language governing permissions and limitations
15 *    under the License.
16 **/
17
18 package org.openflow.protocol;
19
20 import java.util.List;
21
22 import junit.framework.TestCase;
23
24 import org.jboss.netty.buffer.ChannelBuffer;
25 import org.jboss.netty.buffer.ChannelBuffers;
26 import org.openflow.protocol.factory.BasicFactory;
27 import org.openflow.protocol.factory.OFMessageFactory;
28 import org.openflow.protocol.statistics.OFFlowStatisticsRequest;
29 import org.openflow.protocol.statistics.OFStatisticsType;
30 import org.openflow.protocol.statistics.OFVendorStatistics;
31 import org.openflow.util.OFTestCase;
32
33 public class OFStatisticsRequestTest extends OFTestCase {
34     public void testOFFlowStatisticsRequest() throws Exception {
35         byte[] packet = new byte[] { 0x01, 0x10, 0x00, 0x38, 0x00, 0x00, 0x00,
36                 0x16, 0x00, 0x01, 0x00, 0x00, (byte) 0xff, (byte) 0xff,
37                 (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41                 (byte) 0xff, 0x00, (byte) 0xff, (byte) 0xff };
42
43         OFMessageFactory factory = new BasicFactory();
44         ChannelBuffer packetBuf = ChannelBuffers.wrappedBuffer(packet);
45         List<OFMessage> msg = factory.parseMessage(packetBuf);
46         TestCase.assertNotNull(msg);
47         TestCase.assertEquals(msg.size(), 1);
48         TestCase.assertTrue(msg.get(0) instanceof OFStatisticsRequest);
49         OFStatisticsRequest sr = (OFStatisticsRequest) msg.get(0);
50         TestCase.assertEquals(OFStatisticsType.FLOW, sr.getStatisticType());
51         TestCase.assertEquals(1, sr.getStatistics().size());
52         TestCase.assertTrue(sr.getStatistics().get(0) instanceof OFFlowStatisticsRequest);
53     }
54
55     public void testOFStatisticsRequestVendor() throws Exception {
56         byte[] packet = new byte[] { 0x01, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00,
57                 0x63, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
58                 0x4c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59                 0x01, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x20,
60                 (byte) 0xe0, 0x00, 0x11, 0x00, 0x0c, 0x29, (byte) 0xc5,
61                 (byte) 0x95, 0x57, 0x02, 0x25, 0x5c, (byte) 0xca, 0x00, 0x02,
62                 (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
63                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x50, 0x04,
64                 0x00, 0x00, 0x00, 0x00, (byte) 0xff, 0x00, 0x00, 0x00,
65                 (byte) 0xff, (byte) 0xff, 0x4e, 0x20 };
66
67         OFMessageFactory factory = new BasicFactory();
68         ChannelBuffer packetBuf = ChannelBuffers.wrappedBuffer(packet);
69         List<OFMessage> msg = factory.parseMessage(packetBuf);
70         TestCase.assertNotNull(msg);
71         TestCase.assertEquals(msg.size(), 1);
72         TestCase.assertTrue(msg.get(0) instanceof OFStatisticsRequest);
73         OFStatisticsRequest sr = (OFStatisticsRequest) msg.get(0);
74         TestCase.assertEquals(OFStatisticsType.VENDOR, sr.getStatisticType());
75         TestCase.assertEquals(1, sr.getStatistics().size());
76         TestCase.assertTrue(sr.getStatistics().get(0) instanceof OFVendorStatistics);
77         TestCase.assertEquals(68, ((OFVendorStatistics)sr.getStatistics().get(0)).getLength());
78     }
79 }