private void assertKeySet(Context ctx, boolean withoutPulling, String... keys) {
    List<String> keyList =
        createArrayList(
            withoutPulling && ctx instanceof PullableMappedContext
                ? ((PullableMappedContext) ctx).keySetWithoutPulling()
                : ctx.keySet());
    Collections.sort(keyList);

    assertArrayEquals(keys, keyList.toArray(new String[keyList.size()]));
  }
Ejemplo n.º 2
0
  @Test
  public void testHandleMessageWithContext() throws Exception {
    IOFSwitch sw = createMock(IOFSwitch.class);
    expect(sw.getId()).andReturn(DatapathId.NONE).anyTimes();

    IOFMessageListener test1 = createMock(IOFMessageListener.class);
    expect(test1.getName()).andReturn("test1").anyTimes();
    expect(test1.isCallbackOrderingPrereq((OFType) anyObject(), (String) anyObject()))
        .andReturn(false)
        .anyTimes();
    expect(test1.isCallbackOrderingPostreq((OFType) anyObject(), (String) anyObject()))
        .andReturn(false)
        .anyTimes();
    FloodlightContext cntx = new FloodlightContext();
    expect(test1.receive(same(sw), same(pi), same(cntx))).andReturn(Command.CONTINUE);

    IOFMessageListener test2 = createMock(IOFMessageListener.class);
    expect(test2.getName()).andReturn("test2").anyTimes();
    expect(test2.isCallbackOrderingPrereq((OFType) anyObject(), (String) anyObject()))
        .andReturn(false)
        .anyTimes();
    expect(test2.isCallbackOrderingPostreq((OFType) anyObject(), (String) anyObject()))
        .andReturn(false)
        .anyTimes();
    // test2 will not receive any message!

    replay(test1, test2, sw);
    controller.addOFMessageListener(OFType.PACKET_IN, test1);
    controller.addOFMessageListener(OFType.ERROR, test2);
    controller.handleMessage(sw, pi, cntx);
    verify(test1, test2, sw);

    Ethernet eth =
        IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
    assertArrayEquals(testPacket.serialize(), eth.serialize());
  }