OFOxmTest.java
2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package org.projectfloodlight.protocol;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.projectfloodlight.openflow.protocol.OFFactories;
import org.projectfloodlight.openflow.protocol.OFVersion;
import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
import org.projectfloodlight.openflow.protocol.oxm.OFOxmIpv4Src;
import org.projectfloodlight.openflow.protocol.oxm.OFOxmIpv4SrcMasked;
import org.projectfloodlight.openflow.protocol.oxm.OFOxms;
import org.projectfloodlight.openflow.types.IPv4Address;
import org.projectfloodlight.openflow.types.IPv4AddressWithMask;
public class OFOxmTest {
private OFOxms oxms;
@Before
public void setup() {
oxms = OFFactories.getFactory(OFVersion.OF_13).oxms();
}
@Test
public void testGetCanonicalFullMask() {
IPv4AddressWithMask empty = IPv4AddressWithMask.of("0.0.0.0/0");
assertEquals(IPv4Address.FULL_MASK, empty.getMask());
OFOxmIpv4SrcMasked ipv4SrcMasked = oxms.ipv4SrcMasked(empty.getValue(), empty.getMask());
// canonicalize should remove /0
assertNull(ipv4SrcMasked.getCanonical());
}
@Test
public void testGetCanonicalNoMask() {
IPv4AddressWithMask fullIp = IPv4AddressWithMask.of("1.2.3.4/32");
assertEquals(IPv4Address.NO_MASK, fullIp.getMask());
OFOxmIpv4SrcMasked ipv4SrcMasked = oxms.ipv4SrcMasked(fullIp.getValue(), fullIp.getMask());
assertTrue(ipv4SrcMasked.isMasked());
assertEquals(IPv4Address.NO_MASK, ipv4SrcMasked.getMask());
// canonicalize should convert the masked oxm to the non-masked one
OFOxm<IPv4Address> canonical = ipv4SrcMasked.getCanonical();
assertThat(canonical, CoreMatchers.instanceOf(OFOxmIpv4Src.class));
assertFalse(canonical.isMasked());
}
@Test
public void testGetCanonicalNormalMask() {
IPv4AddressWithMask ip = IPv4AddressWithMask.of("1.2.3.0/24");
OFOxmIpv4SrcMasked ipv4SrcMasked = oxms.ipv4SrcMasked(ip.getValue(), ip.getMask());
assertTrue(ipv4SrcMasked.isMasked());
// canonicalize should convert the masked oxm to the non-masked one
OFOxm<IPv4Address> canonical = ipv4SrcMasked.getCanonical();
assertEquals(ipv4SrcMasked, canonical);
}
}