@Test
public void testReadRulesFromStorage() throws Exception {

    // add 2 rules first
    FirewallRule rule = new FirewallRule();
    rule.in_port = OFPort.of(2);
    rule.dl_src = MacAddress.of("00:00:00:00:00:01");
    rule.dl_dst = MacAddress.of("00:00:00:00:00:02");
    rule.priority = 1;
    rule.action = FirewallRule.FirewallAction.DROP;
    firewall.addRule(rule);
    rule = new FirewallRule();
    rule.in_port = OFPort.of(3);
    rule.dl_src = MacAddress.of("00:00:00:00:00:02");
    rule.dl_dst = MacAddress.of("00:00:00:00:00:01");
    rule.nw_proto = IpProtocol.TCP;
    rule.any_nw_proto = false;
    rule.tp_dst = TransportPort.of(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, OFPort.of(2));
    assertEquals(r.priority, 1);
    assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:01"));
    assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:02"));
    assertEquals(r.action, FirewallRule.FirewallAction.DROP);
    // verify rule 2
    r = rules.get(1);
    assertEquals(r.in_port, OFPort.of(3));
    assertEquals(r.priority, 2);
    assertEquals(r.dl_src, MacAddress.of("00:00:00:00:00:02"));
    assertEquals(r.dl_dst, MacAddress.of("00:00:00:00:00:01"));
    assertEquals(r.nw_proto, IpProtocol.TCP);
    assertEquals(r.tp_dst, TransportPort.of(80));
    assertEquals(r.any_nw_proto, false);
    assertEquals(r.action, FirewallRule.FirewallAction.ALLOW);
}