@Before
 public void startUp() {
   provider.providerRegistry = registry;
   provider.controller = controller;
   provider.activate();
   assertNotNull("listener should be registered", registry.listener);
 }
 @After
 public void teardown() {
   provider.deactivate();
   assertNull("listeners shouldn't be registered", registry.listener);
   provider.controller = null;
   provider.providerRegistry = null;
 }
  @Test
  public void emit() {

    MacAddress mac1 = MacAddress.of("00:00:00:11:00:01");
    MacAddress mac2 = MacAddress.of("00:00:00:22:00:02");

    ARP arp = new ARP();
    arp.setSenderProtocolAddress(ANY)
        .setSenderHardwareAddress(mac1.getBytes())
        .setTargetHardwareAddress(mac2.getBytes())
        .setTargetProtocolAddress(ANY)
        .setHardwareType((short) 0)
        .setProtocolType((short) 0)
        .setHardwareAddressLength((byte) 6)
        .setProtocolAddressLength((byte) 4)
        .setOpCode((byte) 0);

    Ethernet eth = new Ethernet();
    eth.setVlanID(VLANID)
        .setEtherType(Ethernet.TYPE_ARP)
        .setSourceMACAddress("00:00:00:11:00:01")
        .setDestinationMACAddress("00:00:00:22:00:02")
        .setPayload(arp);

    // the should-be working setup.
    OutboundPacket passPkt = outPacket(DID, TR, eth);
    sw.setRole(RoleState.MASTER);
    provider.emit(passPkt);
    assertEquals("invalid switch", sw, controller.current);
    assertEquals("message not sent", PLIST.size(), sw.sent.size());
    sw.sent.clear();

    // wrong Role
    // sw.setRole(RoleState.SLAVE);
    // provider.emit(passPkt);
    // assertEquals("invalid switch", sw, controller.current);
    // assertEquals("message sent incorrectly", 0, sw.sent.size());

    // sw.setRole(RoleState.MASTER);

    // missing switch
    OutboundPacket swFailPkt = outPacket(DID_MISSING, TR, eth);
    provider.emit(swFailPkt);
    assertNull("invalid switch", controller.current);
    assertEquals("message sent incorrectly", 0, sw.sent.size());

    // to missing port
    // OutboundPacket portFailPkt = outPacket(DID, TR_MISSING, eth);
    // provider.emit(portFailPkt);
    // assertEquals("extra message sent", 1, sw.sent.size());

  }
 @Test(expected = IllegalArgumentException.class)
 public void wrongScheme() {
   sw.setRole(RoleState.MASTER);
   OutboundPacket schemeFailPkt = outPacket(DID_WRONG, TR, null);
   provider.emit(schemeFailPkt);
   assertEquals("message sent incorrectly", 0, sw.sent.size());
 }