Пример #1
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    mockFloodlightProvider = getMockFloodlightProvider();
    hub = new Hub();
    mockFloodlightProvider.addOFMessageListener(OFType.PACKET_IN, hub);
    hub.setFloodlightProvider(mockFloodlightProvider);

    // Build our test packet
    this.testPacket =
        new Ethernet()
            .setDestinationMACAddress("00:11:22:33:44:55")
            .setSourceMACAddress("00:44:33:22:11:00")
            .setEtherType(Ethernet.TYPE_IPv4)
            .setPayload(
                new IPv4()
                    .setTtl((byte) 128)
                    .setSourceAddress("192.168.1.1")
                    .setDestinationAddress("192.168.1.2")
                    .setPayload(
                        new UDP()
                            .setSourcePort((short) 5000)
                            .setDestinationPort((short) 5001)
                            .setPayload(new Data(new byte[] {0x01}))));
    this.testPacketSerialized = testPacket.serialize();

    // Build the PacketIn
    this.packetIn =
        ((OFPacketIn) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_IN))
            .setBufferId(-1)
            .setInPort((short) 1)
            .setPacketData(this.testPacketSerialized)
            .setReason(OFPacketInReason.NO_MATCH)
            .setTotalLength((short) this.testPacketSerialized.length);
  }
Пример #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());
  }
Пример #3
0
 /**
  * @see packetOutMultiPort Accepts an IPacket instead of raw packet data. Note that the inPort and
  *     switch can be different than the packet in switch/port
  */
 public void packetOutMultiPort(
     IPacket packet, IOFSwitch sw, short inPort, Set<Integer> outPorts, FloodlightContext cntx) {
   packetOutMultiPort(packet.serialize(), sw, inPort, outPorts, cntx);
 }
Пример #4
0
  public void doSetUp(HARole role) throws Exception {
    super.setUp();
    FloodlightModuleContext fmc = new FloodlightModuleContext();
    FloodlightProvider cm = new FloodlightProvider();

    fmc.addConfigParam(cm, "role", role.toString());
    controller = (Controller) cm.getServiceImpls().get(IFloodlightProviderService.class);
    fmc.addService(IFloodlightProviderService.class, controller);

    MemoryStorageSource memstorage = new MemoryStorageSource();
    fmc.addService(IStorageSourceService.class, memstorage);

    RestApiServer restApi = new RestApiServer();
    fmc.addService(IRestApiService.class, restApi);

    ThreadPool threadPool = new ThreadPool();
    fmc.addService(IThreadPoolService.class, threadPool);

    MockSwitchManager switchService = new MockSwitchManager();
    fmc.addService(IOFSwitchService.class, switchService);

    PktInProcessingTime ppt = new PktInProcessingTime();
    fmc.addService(IPktInProcessingTimeService.class, ppt);

    // TODO: should mock IDebugCounterService and make sure
    // the expected counters are updated.
    DebugCounterServiceImpl debugCounterService = new DebugCounterServiceImpl();
    fmc.addService(IDebugCounterService.class, debugCounterService);

    DebugEventService debugEventService = new DebugEventService();
    fmc.addService(IDebugEventService.class, debugEventService);

    IShutdownService shutdownService = createMock(IShutdownService.class);
    shutdownService.registerShutdownListener(anyObject(IShutdownListener.class));
    expectLastCall().anyTimes();
    replay(shutdownService);
    fmc.addService(IShutdownService.class, shutdownService);
    verify(shutdownService);

    tp = new MockThreadPoolService();
    fmc.addService(IThreadPoolService.class, tp);

    syncService = new MockSyncService();
    fmc.addService(ISyncService.class, syncService);

    ppt.init(fmc);
    restApi.init(fmc);
    threadPool.init(fmc);
    memstorage.init(fmc);
    tp.init(fmc);
    debugCounterService.init(fmc);
    debugEventService.init(fmc);
    syncService.init(fmc);
    cm.init(fmc);

    ppt.startUp(fmc);
    restApi.startUp(fmc);
    threadPool.startUp(fmc);
    memstorage.startUp(fmc);
    tp.startUp(fmc);
    debugCounterService.startUp(fmc);
    debugEventService.startUp(fmc);
    syncService.startUp(fmc);
    cm.startUp(fmc);

    testPacket =
        new Ethernet()
            .setSourceMACAddress("00:44:33:22:11:00")
            .setDestinationMACAddress("00:11:22:33:44:55")
            .setEtherType(EthType.ARP)
            .setPayload(
                new ARP()
                    .setHardwareType(ARP.HW_TYPE_ETHERNET)
                    .setProtocolType(ARP.PROTO_TYPE_IP)
                    .setHardwareAddressLength((byte) 6)
                    .setProtocolAddressLength((byte) 4)
                    .setOpCode(ARP.OP_REPLY)
                    .setSenderHardwareAddress(Ethernet.toMACAddress("00:44:33:22:11:00"))
                    .setSenderProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.1"))
                    .setTargetHardwareAddress(Ethernet.toMACAddress("00:11:22:33:44:55"))
                    .setTargetProtocolAddress(IPv4.toIPv4AddressBytes("192.168.1.2")));
    byte[] testPacketSerialized = testPacket.serialize();

    // The specific factory can be obtained from the switch, but we don't have one
    pi =
        (OFPacketIn)
            factory
                .buildPacketIn()
                .setBufferId(OFBufferId.NO_BUFFER)
                .setInPort(OFPort.of(1))
                .setData(testPacketSerialized)
                .setReason(OFPacketInReason.NO_MATCH)
                .setTotalLen(testPacketSerialized.length)
                .build();
  }
Пример #5
0
  /**
   * Pushes a packet-out to a switch. If bufferId != BUFFER_ID_NONE we assume that the packetOut
   * switch is the same as the packetIn switch and we will use the bufferId. In this case the packet
   * can be null Caller needs to make sure that inPort and outPort differs
   *
   * @param packet packet data to send.
   * @param sw switch from which packet-out is sent
   * @param bufferId bufferId
   * @param inPort input port
   * @param outPort output port
   * @param cntx context of the packet
   * @param flush force to flush the packet.
   */
  @LogMessageDocs({
    @LogMessageDoc(
        level = "ERROR",
        message =
            "BufferId is not and packet data is null. "
                + "Cannot send packetOut. "
                + "srcSwitch={dpid} inPort={port} outPort={port}",
        explanation = "The switch send a malformed packet-in." + "The packet will be dropped",
        recommendation = LogMessageDoc.REPORT_SWITCH_BUG),
    @LogMessageDoc(
        level = "ERROR",
        message = "Failure writing packet out",
        explanation = "An I/O error occurred while writing a " + "packet out to a switch",
        recommendation = LogMessageDoc.CHECK_SWITCH)
  })
  public void pushPacket(
      IPacket packet,
      IOFSwitch sw,
      int bufferId,
      short inPort,
      short outPort,
      FloodlightContext cntx,
      boolean flush) {

    if (log.isTraceEnabled()) {
      log.trace("PacketOut srcSwitch={} inPort={} outPort={}", new Object[] {sw, inPort, outPort});
    }

    OFPacketOut po =
        (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);

    // set actions
    List<OFAction> actions = new ArrayList<OFAction>();
    actions.add(new OFActionOutput(outPort, (short) 0xffff));

    po.setActions(actions).setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);
    short poLength = (short) (po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH);

    // set buffer_id, in_port
    po.setBufferId(bufferId);
    po.setInPort(inPort);

    // set data - only if buffer_id == -1
    if (po.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
      if (packet == null) {
        log.error(
            "BufferId is not set and packet data is null. "
                + "Cannot send packetOut. "
                + "srcSwitch={} inPort={} outPort={}",
            new Object[] {sw, inPort, outPort});
        return;
      }
      byte[] packetData = packet.serialize();
      poLength += packetData.length;
      po.setPacketData(packetData);
    }

    po.setLength(poLength);

    try {
      counterStore.updatePktOutFMCounterStoreLocal(sw, po);
      messageDamper.write(sw, po, cntx, flush);
    } catch (IOException e) {
      log.error("Failure writing packet out", e);
    }
  }