blob: b18d0ebcbc37e534f428646c3fe571d6f3f742ed [file] [log] [blame]
Yotam Harchola11f38b2013-09-26 15:38:17 -07001package org.projectfloodlight.openflow.types;
2
3import static org.junit.Assert.assertArrayEquals;
4import junit.framework.TestCase;
5
6import org.junit.Test;
7
Andreas Wundsam9667a162013-10-21 12:58:16 -07008public class OFPortBitMapTest extends TestCase {
Yotam Harchola11f38b2013-09-26 15:38:17 -07009
10 @Test
Andreas Wundsam9667a162013-10-21 12:58:16 -070011 public void testOFPortBitMap() {
Yotam Harchola11f38b2013-09-26 15:38:17 -070012 Boolean[] on = new Boolean[128];
13 for (int i = 0; i < 128; i++) {
14 on[i] = false;
15 }
16
Andreas Wundsam9667a162013-10-21 12:58:16 -070017 OFPortBitMap.Builder builder = new OFPortBitMap.Builder();
Yotam Harchola11f38b2013-09-26 15:38:17 -070018
19 for (int i = 0; i < 128; i += 3) {
20 OFPort p = OFPort.of(i);
21 builder.set(p);
22 on[p.getPortNumber()] = true;
23 }
24
25 // Test that all ports that were added are actually on, and all other ports are off
Andreas Wundsam9667a162013-10-21 12:58:16 -070026 OFPortBitMap portmap = builder.build();
Yotam Harchol595c6442013-09-27 16:29:08 -070027 //System.out.println(portmap);
Yotam Harchola11f38b2013-09-26 15:38:17 -070028 Boolean[] actual = new Boolean[128];
29 for (int i = 0; i < 128; i++) {
30 actual[i] = false;
31 }
32 for (int i = 0; i < 128; i++) {
33 actual[i] = portmap.isOn(OFPort.of(i));
34 }
35 assertArrayEquals(on, actual);
36
37 // Turn some ports off
38 for (int i = 0; i < 128; i += 7) {
39 on[i] = false;
40 builder.unset(OFPort.of(i));
41 }
42
43 // Test again
44 portmap = builder.build();
45 actual = new Boolean[128];
46 for (int i = 0; i < 128; i++) {
47 actual[i] = false;
48 }
49 for (int i = 0; i < 128; i++) {
50 actual[i] = portmap.isOn(OFPort.of(i));
51 }
52 assertArrayEquals(on, actual);
53 }
54}