@Test
public void testReadRulesFromStorage() throws Exception {

    // add 2 rules first
    FirewallRule rule = new FirewallRule();
    rule.in_port = 2;
    rule.dl_src = MACAddress.valueOf("00:00:00:00:00:01").toLong();
    rule.dl_dst = MACAddress.valueOf("00:00:00:00:00:02").toLong();
    rule.priority = 1;
    rule.action = FirewallRule.FirewallAction.DENY;
    firewall.addRule(rule);
    rule = new FirewallRule();
    rule.in_port = 3;
    rule.dl_src = MACAddress.valueOf("00:00:00:00:00:02").toLong();
    rule.dl_dst = MACAddress.valueOf("00:00:00:00:00:01").toLong();
    rule.nw_proto = IPv4.PROTOCOL_TCP;
    rule.wildcard_nw_proto = false;
    rule.tp_dst = 80;
    rule.priority = 2;
    rule.action = FirewallRule.FirewallAction.ALLOW;
    firewall.addRule(rule);
    List<FirewallRule> rules = firewall.readRulesFromStorage();
    // verify rule 1
    FirewallRule r = rules.get(0);
    assertEquals(r.in_port, 2);
    assertEquals(r.priority, 1);
    assertEquals(r.dl_src, MACAddress.valueOf("00:00:00:00:00:01").toLong());
    assertEquals(r.dl_dst, MACAddress.valueOf("00:00:00:00:00:02").toLong());
    assertEquals(r.action, FirewallRule.FirewallAction.DENY);
    // verify rule 2
    r = rules.get(1);
    assertEquals(r.in_port, 3);
    assertEquals(r.priority, 2);
    assertEquals(r.dl_src, MACAddress.valueOf("00:00:00:00:00:02").toLong());
    assertEquals(r.dl_dst, MACAddress.valueOf("00:00:00:00:00:01").toLong());
    assertEquals(r.nw_proto, IPv4.PROTOCOL_TCP);
    assertEquals(r.tp_dst, 80);
    assertEquals(r.wildcard_nw_proto, false);
    assertEquals(r.action, FirewallRule.FirewallAction.ALLOW);
}