blob: 7f5ab5da263d0d35895bda95180a4b950de5500c [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() {
Andreas Wundsam28c99752013-10-22 16:51:25 -070012 Boolean[] on = new Boolean[127];
13 for (int i = 0; i < 127; i++) {
Yotam Harchola11f38b2013-09-26 15:38:17 -070014 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
Andreas Wundsam28c99752013-10-22 16:51:25 -070019 for (int i = 0; i < 127; i += 3) {
Yotam Harchola11f38b2013-09-26 15:38:17 -070020 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);
Andreas Wundsam28c99752013-10-22 16:51:25 -070028 Boolean[] actual = new Boolean[127];
29 for (int i = 0; i < 127; i++) {
Yotam Harchola11f38b2013-09-26 15:38:17 -070030 actual[i] = false;
31 }
Andreas Wundsam28c99752013-10-22 16:51:25 -070032 for (int i = 0; i < 127; i++) {
Yotam Harchola11f38b2013-09-26 15:38:17 -070033 actual[i] = portmap.isOn(OFPort.of(i));
34 }
35 assertArrayEquals(on, actual);
36
37 // Turn some ports off
Andreas Wundsam28c99752013-10-22 16:51:25 -070038 for (int i = 0; i < 127; i += 7) {
Yotam Harchola11f38b2013-09-26 15:38:17 -070039 on[i] = false;
40 builder.unset(OFPort.of(i));
41 }
42
43 // Test again
44 portmap = builder.build();
Andreas Wundsam28c99752013-10-22 16:51:25 -070045 actual = new Boolean[127];
46 for (int i = 0; i < 127; i++) {
Yotam Harchola11f38b2013-09-26 15:38:17 -070047 actual[i] = false;
48 }
Andreas Wundsam28c99752013-10-22 16:51:25 -070049 for (int i = 0; i < 127; i++) {
Yotam Harchola11f38b2013-09-26 15:38:17 -070050 actual[i] = portmap.isOn(OFPort.of(i));
51 }
52 assertArrayEquals(on, actual);
53 }
54}