Java 类org.easymock.CaptureType 实例源码

项目:kafka-0.11.0.0-src-with-comment    文件:WorkerSinkTaskTest.java   
@Test
public void testMissingTimestampPropagation() throws Exception {
    expectInitializeTask();
    expectConsumerPoll(1, RecordBatch.NO_TIMESTAMP, TimestampType.CREATE_TIME);
    expectConversionAndTransformation(1);

    Capture<Collection<SinkRecord>> records = EasyMock.newCapture(CaptureType.ALL);

    sinkTask.put(EasyMock.capture(records));

    PowerMock.replayAll();

    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();
    workerTask.iteration();

    SinkRecord record = records.getValue().iterator().next();

    // we expect null for missing timestamp, the sentinel value of Record.NO_TIMESTAMP is Kafka's API
    assertEquals(null, record.timestamp());
    assertEquals(TimestampType.CREATE_TIME, record.timestampType());

    PowerMock.verifyAll();
}
项目:kafka-0.11.0.0-src-with-comment    文件:WorkerSinkTaskTest.java   
@Test
public void testTimestampPropagation() throws Exception {
    final Long timestamp = System.currentTimeMillis();
    final TimestampType timestampType = TimestampType.CREATE_TIME;

    expectInitializeTask();
    expectConsumerPoll(1, timestamp, timestampType);
    expectConversionAndTransformation(1);

    Capture<Collection<SinkRecord>> records = EasyMock.newCapture(CaptureType.ALL);

    sinkTask.put(EasyMock.capture(records));

    PowerMock.replayAll();

    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();
    workerTask.iteration();

    SinkRecord record = records.getValue().iterator().next();

    assertEquals(timestamp, record.timestamp());
    assertEquals(timestampType, record.timestampType());

    PowerMock.verifyAll();
}
项目:pentaho-mongodb-plugin    文件:MongoDbOutputTest.java   
/**
 * Tests if mongo output configuration contains excessive fields in step input against mongo output fields, we
 * generate a mockLog record about the fields will not be used in mongo output.
 *
 * @throws Exception
 */
@Test public void testStepLogSkippedFields() throws Exception {
  MongoDbOutput output = prepareMongoDbOutputMock();

  final String[] metaNames = new String[] { "a1", "a2", "a3" };
  String[] mongoNames = new String[] { "a1", "a2" };
  Capture<String> loggerCapture = new Capture<String>( CaptureType.ALL );
  output.logBasic( EasyMock.capture( loggerCapture ) );
  EasyMock.replay( output );
  RowMetaInterface rmi = getStubRowMetaInterface( metaNames );
  List<MongoDbOutputMeta.MongoField> mongoFields = getMongoFields( mongoNames );

  output.checkInputFieldsMatch( rmi, mongoFields );
  List<String> logRecords = loggerCapture.getValues();

  Assert.assertEquals( "We have one mockLog record generated", 1, logRecords.size() );
  Assert.assertTrue( "We have a mockLog record mentions that 'a3' field will not be used.",
    logRecords.get( 0 ).contains( "a3" ) );
}
项目:open-kilda    文件:ReplaceInstallFlowTest.java   
/**
 * Runs test case.
 *
 * @param value       data string from json resource file
 * @param flowCommand OFFlowAdd instance to compare result with
 * @throws InterruptedException if test was interrupted during run
 */
private void runTest(final String value, final OFFlowAdd flowCommand, final OFMeterMod meterCommand,
                     final OFFlowAdd reverseFlowCommand, final OFMeterMod reverseMeterCommand)
        throws InterruptedException {
    // construct kafka message
    ConsumerRecord<String, String> record = new ConsumerRecord<>("", 0, 0, "", value);

    // create parser instance
    KafkaMessageCollector.ParseRecord parseRecord = collector.new ParseRecord(record);
    // init test mocks
    Capture<OFFlowAdd> flowAddCapture = flowCommand == null ? null : newCapture(CaptureType.ALL);
    Capture<OFMeterMod> meterAddCapture = meterCommand == null ? null : newCapture(CaptureType.ALL);
    prepareMocks(flowAddCapture, meterAddCapture, reverseFlowCommand != null, reverseMeterCommand != null);

    // run parser and wait for termination or timeout
    parseRecordExecutor.execute(parseRecord);
    parseRecordExecutor.shutdown();
    parseRecordExecutor.awaitTermination(10, TimeUnit.SECONDS);

    // verify results
    if (meterCommand != null) {
        assertEquals(meterCommand, meterAddCapture.getValues().get(0));
        if (reverseMeterCommand != null) {
            assertEquals(reverseMeterCommand, meterAddCapture.getValues().get(1));
        }
    }
    if (flowCommand != null) {
        assertEquals(flowCommand, flowAddCapture.getValues().get(0));
        if (reverseFlowCommand != null) {
            assertEquals(reverseFlowCommand, flowAddCapture.getValues().get(1));
        }
    }
}
项目:kafka-0.11.0.0-src-with-comment    文件:WorkerSinkTaskTest.java   
@Test
public void testPollRedelivery() throws Exception {
    expectInitializeTask();
    expectPollInitialAssignment();

    // If a retriable exception is thrown, we should redeliver the same batch, pausing the consumer in the meantime
    expectConsumerPoll(1);
    expectConversionAndTransformation(1);
    Capture<Collection<SinkRecord>> records = EasyMock.newCapture(CaptureType.ALL);
    sinkTask.put(EasyMock.capture(records));
    EasyMock.expectLastCall().andThrow(new RetriableException("retry"));
    // Pause
    HashSet<TopicPartition> partitions = new HashSet<>(asList(TOPIC_PARTITION, TOPIC_PARTITION2));
    EasyMock.expect(consumer.assignment()).andReturn(partitions);
    consumer.pause(partitions);
    PowerMock.expectLastCall();

    // Retry delivery should succeed
    expectConsumerPoll(0);
    sinkTask.put(EasyMock.capture(records));
    EasyMock.expectLastCall();
    // And unpause
    EasyMock.expect(consumer.assignment()).andReturn(partitions);
    consumer.resume(singleton(TOPIC_PARTITION));
    PowerMock.expectLastCall();
    consumer.resume(singleton(TOPIC_PARTITION2));
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();
    workerTask.iteration();
    workerTask.iteration();
    workerTask.iteration();

    PowerMock.verifyAll();
}
项目:kafka-0.11.0.0-src-with-comment    文件:WorkerSinkTaskThreadedTest.java   
private Capture<Collection<SinkRecord>> expectPolls(final long pollDelayMs) throws Exception {
    // Stub out all the consumer stream/iterator responses, which we just want to verify occur,
    // but don't care about the exact details here.
    EasyMock.expect(consumer.poll(EasyMock.anyLong())).andStubAnswer(
            new IAnswer<ConsumerRecords<byte[], byte[]>>() {
                @Override
                public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
                    // "Sleep" so time will progress
                    time.sleep(pollDelayMs);
                    ConsumerRecords<byte[], byte[]> records = new ConsumerRecords<>(
                            Collections.singletonMap(
                                    new TopicPartition(TOPIC, PARTITION),
                                    Arrays.asList(
                                            new ConsumerRecord<>(TOPIC, PARTITION, FIRST_OFFSET + recordsReturned, TIMESTAMP, TIMESTAMP_TYPE, 0L, 0, 0, RAW_KEY, RAW_VALUE)
                                    )));
                    recordsReturned++;
                    return records;
                }
            });
    EasyMock.expect(keyConverter.toConnectData(TOPIC, RAW_KEY)).andReturn(new SchemaAndValue(KEY_SCHEMA, KEY)).anyTimes();
    EasyMock.expect(valueConverter.toConnectData(TOPIC, RAW_VALUE)).andReturn(new SchemaAndValue(VALUE_SCHEMA, VALUE)).anyTimes();

    final Capture<SinkRecord> recordCapture = EasyMock.newCapture();
    EasyMock.expect(transformationChain.apply(EasyMock.capture(recordCapture))).andAnswer(new IAnswer<SinkRecord>() {
        @Override
        public SinkRecord answer() {
            return recordCapture.getValue();
        }
    }).anyTimes();

    Capture<Collection<SinkRecord>> capturedRecords = EasyMock.newCapture(CaptureType.ALL);
    sinkTask.put(EasyMock.capture(capturedRecords));
    EasyMock.expectLastCall().anyTimes();
    return capturedRecords;
}
项目:fresco_floodlight    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)).andReturn(true).anyTimes();
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));

    removeDeviceFromContext();
}
项目:fresco_floodlight    文件:ForwardingTest.java   
@Test
public void testForwardNoPathIPv6() throws Exception {
    learnDevicesIPv6(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD))
    .andReturn(true).anyTimes();
    // Reset XID to expected (dependent on prior unit tests)
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetInIPv6, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFloodedIPv6));

    removeDeviceFromContext();
}
项目:fresco_floodlight    文件:HubTest.java   
@Test
public void testFloodNoBufferId() throws Exception {
    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();

    // build our expected flooded packetOut
    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setBufferId(OFBufferId.NO_BUFFER)
        .setXid(1)
        .setInPort(OFPort.of(1))
        .setData(this.testPacketSerialized).build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertTrue(OFMessageUtils.equalsIgnoreXid(m, po));
}
项目:fresco_floodlight    文件:HubTest.java   
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn = this.packetIn.createBuilder()
            .setBufferId(OFBufferId.of(10))
            .setXid(1)
            .build();

    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    // build our expected flooded packetOut
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setXid(1)
        .setBufferId(OFBufferId.of(10))
        .setInPort(OFPort.of(1))
        .build();

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL);
    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:fresco_floodlight    文件:LearningSwitchTest.java   
@Test
public void testFlood() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = factory.buildPacketOut()
        .setInPort(OFPort.of(1))
        .setActions(Arrays.asList((OFAction)factory.actions().output(OFPort.FLOOD, 0xffFFffFF)))
        .setBufferId(OFBufferId.NO_BUFFER)
        .setData(this.testPacketSerialized)
     .build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    expect(mockSwitch.getId()).andReturn(DatapathId.of("00:11:22:33:44:55:66:77")).anyTimes();
    expect(mockSwitch.getOFFactory()).andReturn(factory).anyTimes();
    expect(mockSwitch.write(EasyMock.capture(wc1))).andReturn(true).once(); // expect po

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(OFType.PACKET_IN).get(0);
    // Make sure it's the right listener
    listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    OFPort result = learningSwitch.getFromPortMap(mockSwitch, MacAddress.of("00:44:33:22:11:00"), VlanVid.ofVlan(42));
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), po));

    // Verify the MAC table inside the switch
    assertEquals(OFPort.of(1), result);
}
项目:iTAP-controller    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.isIncomingBroadcastAllowed(DatapathId.of(1L), OFPort.of(1))).andReturn(true).anyTimes();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
                                          OFPort.of(anyShort())))
                                          .andReturn(true)
                                          .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD))
            .andReturn(true).anyTimes();
    // Reset XID to expected (dependent on prior unit tests)
    sw1.write(capture(wc1));
    expectLastCall().once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));
}
项目:iTAP-controller    文件:HubTest.java   
@Test
public void testFloodNoBufferId() throws Exception {
    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();

    // build our expected flooded packetOut
    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setBufferId(OFBufferId.NO_BUFFER)
        .setXid(1)
        .setInPort(OFPort.of(1))
        .setData(this.testPacketSerialized).build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    mockSwitch.write(capture(wc1));

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertTrue(OFMessageUtils.equalsIgnoreXid(m, po));
}
项目:iTAP-controller    文件:HubTest.java   
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn = this.packetIn.createBuilder()
            .setBufferId(OFBufferId.of(10))
            .setXid(1)
            .build();

    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    // build our expected flooded packetOut
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setXid(1)
        .setBufferId(OFBufferId.of(10))
        .setInPort(OFPort.of(1))
        .build();

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL);
    mockSwitch.write(capture(wc1));

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:iTAP-controller    文件:LearningSwitchTest.java   
@Test
public void testFlood() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = factory.buildPacketOut()
        .setInPort(OFPort.of(1))
        .setActions(Arrays.asList((OFAction)factory.actions().output(OFPort.FLOOD, 0xffFFffFF)))
        .setBufferId(OFBufferId.NO_BUFFER)
        .setData(this.testPacketSerialized)
     .build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    expect(mockSwitch.getId()).andReturn(DatapathId.of("00:11:22:33:44:55:66:77")).anyTimes();
    expect(mockSwitch.getOFFactory()).andReturn(factory).anyTimes();
    mockSwitch.write(EasyMock.capture(wc1)); // expect po
    EasyMock.expectLastCall().once();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(OFType.PACKET_IN).get(0);
    // Make sure it's the right listener
    listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    OFPort result = learningSwitch.getFromPortMap(mockSwitch, MacAddress.of("00:44:33:22:11:00"), VlanVid.ofVlan(42));
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), po));

    // Verify the MAC table inside the switch
    assertEquals(OFPort.of(1), result);
}
项目:SDN-Multicast    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)).andReturn(true).anyTimes();
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));

    removeDeviceFromContext();
}
项目:SDN-Multicast    文件:ForwardingTest.java   
@Test
public void testForwardNoPathIPv6() throws Exception {
    learnDevicesIPv6(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD))
    .andReturn(true).anyTimes();
    // Reset XID to expected (dependent on prior unit tests)
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetInIPv6, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFloodedIPv6));

    removeDeviceFromContext();
}
项目:SDN-Multicast    文件:HubTest.java   
@Test
public void testFloodNoBufferId() throws Exception {
    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();

    // build our expected flooded packetOut
    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setBufferId(OFBufferId.NO_BUFFER)
        .setXid(1)
        .setInPort(OFPort.of(1))
        .setData(this.testPacketSerialized).build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertTrue(OFMessageUtils.equalsIgnoreXid(m, po));
}
项目:SDN-Multicast    文件:HubTest.java   
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn = this.packetIn.createBuilder()
            .setBufferId(OFBufferId.of(10))
            .setXid(1)
            .build();

    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    // build our expected flooded packetOut
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setXid(1)
        .setBufferId(OFBufferId.of(10))
        .setInPort(OFPort.of(1))
        .build();

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL);
    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:SDN-Multicast    文件:LearningSwitchTest.java   
@Test
public void testFlood() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = factory.buildPacketOut()
        .setInPort(OFPort.of(1))
        .setActions(Arrays.asList((OFAction)factory.actions().output(OFPort.FLOOD, 0xffFFffFF)))
        .setBufferId(OFBufferId.NO_BUFFER)
        .setData(this.testPacketSerialized)
     .build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    expect(mockSwitch.getId()).andReturn(DatapathId.of("00:11:22:33:44:55:66:77")).anyTimes();
    expect(mockSwitch.getOFFactory()).andReturn(factory).anyTimes();
    expect(mockSwitch.write(EasyMock.capture(wc1))).andReturn(true).once(); // expect po

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(OFType.PACKET_IN).get(0);
    // Make sure it's the right listener
    listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    OFPort result = learningSwitch.getFromPortMap(mockSwitch, MacAddress.of("00:44:33:22:11:00"), VlanVid.ofVlan(42));
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), po));

    // Verify the MAC table inside the switch
    assertEquals(OFPort.of(1), result);
}
项目:NithPointsj    文件:PeerTest.java   
@Override
@Before
public void setUp() throws Exception {
    super.setUp();

    memoryPool = new MemoryPool();
    VersionMessage ver = new VersionMessage(unitTestParams, 100);
    peer = new Peer(unitTestParams, blockChain, ver, memoryPool);
    peer.addWallet(wallet);
    handler = peer.getHandler();
    event = new Capture<DownstreamMessageEvent>(CaptureType.ALL);
    pipeline.sendDownstream(capture(event));
    expectLastCall().anyTimes();
}
项目:arscheduler    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)).andReturn(true).anyTimes();
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));

    removeDeviceFromContext();
}
项目:arscheduler    文件:ForwardingTest.java   
@Test
public void testForwardNoPathIPv6() throws Exception {
    learnDevicesIPv6(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD))
    .andReturn(true).anyTimes();
    // Reset XID to expected (dependent on prior unit tests)
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetInIPv6, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFloodedIPv6));

    removeDeviceFromContext();
}
项目:arscheduler    文件:HubTest.java   
@Test
public void testFloodNoBufferId() throws Exception {
    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();

    // build our expected flooded packetOut
    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setBufferId(OFBufferId.NO_BUFFER)
        .setXid(1)
        .setInPort(OFPort.of(1))
        .setData(this.testPacketSerialized).build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertTrue(OFMessageUtils.equalsIgnoreXid(m, po));
}
项目:arscheduler    文件:HubTest.java   
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn = this.packetIn.createBuilder()
            .setBufferId(OFBufferId.of(10))
            .setXid(1)
            .build();

    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    // build our expected flooded packetOut
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setXid(1)
        .setBufferId(OFBufferId.of(10))
        .setInPort(OFPort.of(1))
        .build();

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL);
    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:arscheduler    文件:LearningSwitchTest.java   
@Test
public void testFlood() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = factory.buildPacketOut()
        .setInPort(OFPort.of(1))
        .setActions(Arrays.asList((OFAction)factory.actions().output(OFPort.FLOOD, 0xffFFffFF)))
        .setBufferId(OFBufferId.NO_BUFFER)
        .setData(this.testPacketSerialized)
     .build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    expect(mockSwitch.getId()).andReturn(DatapathId.of("00:11:22:33:44:55:66:77")).anyTimes();
    expect(mockSwitch.getOFFactory()).andReturn(factory).anyTimes();
    expect(mockSwitch.write(EasyMock.capture(wc1))).andReturn(true).once(); // expect po

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(OFType.PACKET_IN).get(0);
    // Make sure it's the right listener
    listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    OFPort result = learningSwitch.getFromPortMap(mockSwitch, MacAddress.of("00:44:33:22:11:00"), VlanVid.ofVlan(42));
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), po));

    // Verify the MAC table inside the switch
    assertEquals(OFPort.of(1), result);
}
项目:QoS-floodlight    文件:HubTest.java   
@Test
public void testFloodNoBufferId() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT))
        .setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
        .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
        .setBufferId(-1)
        .setInPort((short) 1)
        .setPacketData(this.testPacketSerialized);
    po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU()
            + this.testPacketSerialized.length);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
    Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL);

    mockSwitch.write(capture(wc1), capture(bc1));

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:QoS-floodlight    文件:HubTest.java   
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn.setBufferId(10);

    // build our expected flooded packetOut
    OFPacketOut po = ((OFPacketOut) mockFloodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT))
        .setActions(Arrays.asList(new OFAction[] {new OFActionOutput().setPort(OFPort.OFPP_FLOOD.getValue())}))
        .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH)
        .setBufferId(10)
        .setInPort((short) 1);
    po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLengthU());

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);
    Capture<FloodlightContext> bc1 = new Capture<FloodlightContext>(CaptureType.ALL);

    mockSwitch.write(capture(wc1), capture(bc1));

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:QoS-floodlight    文件:StaticFlowTests.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    staticFlowEntryPusher = new StaticFlowEntryPusher();
    storage = createStorageWithFlowEntries();
    dpid = HexString.toLong(TestSwitch1DPID);

    mockSwitch = createNiceMock(IOFSwitch.class);
    writeCapture = new Capture<OFMessage>(CaptureType.ALL);
    contextCapture = new Capture<FloodlightContext>(CaptureType.ALL);
    writeCaptureList = new Capture<List<OFMessage>>(CaptureType.ALL);

    //OFMessageSafeOutStream mockOutStream = createNiceMock(OFMessageSafeOutStream.class);
    mockSwitch.write(capture(writeCapture), capture(contextCapture));
    expectLastCall().anyTimes();
    mockSwitch.write(capture(writeCaptureList), capture(contextCapture));
    expectLastCall().anyTimes();
    mockSwitch.flush();
    expectLastCall().anyTimes();


    FloodlightModuleContext fmc = new FloodlightModuleContext();
    fmc.addService(IStorageSourceService.class, storage);

    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    Map<Long, IOFSwitch> switchMap = new HashMap<Long, IOFSwitch>();
    switchMap.put(dpid, mockSwitch);
    // NO ! expect(mockFloodlightProvider.getSwitches()).andReturn(switchMap).anyTimes();
    mockFloodlightProvider.setSwitches(switchMap);
    fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
    RestApiServer restApi = new RestApiServer();
    fmc.addService(IRestApiService.class, restApi);
    restApi.init(fmc);
    staticFlowEntryPusher.init(fmc);
    staticFlowEntryPusher.startUp(fmc);    // again, to hack unittest
}
项目:floodlight1.2-delay    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)).andReturn(true).anyTimes();
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));

    removeDeviceFromContext();
}
项目:floodlight1.2-delay    文件:ForwardingTest.java   
@Test
public void testForwardNoPathIPv6() throws Exception {
    learnDevicesIPv6(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD))
    .andReturn(true).anyTimes();
    // Reset XID to expected (dependent on prior unit tests)
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetInIPv6, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFloodedIPv6));

    removeDeviceFromContext();
}
项目:floodlight1.2-delay    文件:HubTest.java   
@Test
public void testFloodNoBufferId() throws Exception {
    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();

    // build our expected flooded packetOut
    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setBufferId(OFBufferId.NO_BUFFER)
        .setXid(1)
        .setInPort(OFPort.of(1))
        .setData(this.testPacketSerialized).build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertTrue(OFMessageUtils.equalsIgnoreXid(m, po));
}
项目:floodlight1.2-delay    文件:HubTest.java   
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn = this.packetIn.createBuilder()
            .setBufferId(OFBufferId.of(10))
            .setXid(1)
            .build();

    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    // build our expected flooded packetOut
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setXid(1)
        .setBufferId(OFBufferId.of(10))
        .setInPort(OFPort.of(1))
        .build();

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL);
    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:floodlight1.2-delay    文件:LearningSwitchTest.java   
@Test
public void testFlood() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = factory.buildPacketOut()
        .setInPort(OFPort.of(1))
        .setActions(Arrays.asList((OFAction)factory.actions().output(OFPort.FLOOD, 0xffFFffFF)))
        .setBufferId(OFBufferId.NO_BUFFER)
        .setData(this.testPacketSerialized)
     .build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    expect(mockSwitch.getId()).andReturn(DatapathId.of("00:11:22:33:44:55:66:77")).anyTimes();
    expect(mockSwitch.getOFFactory()).andReturn(factory).anyTimes();
    expect(mockSwitch.write(EasyMock.capture(wc1))).andReturn(true).once(); // expect po

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(OFType.PACKET_IN).get(0);
    // Make sure it's the right listener
    listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    OFPort result = learningSwitch.getFromPortMap(mockSwitch, MacAddress.of("00:44:33:22:11:00"), VlanVid.ofVlan(42));
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), po));

    // Verify the MAC table inside the switch
    assertEquals(OFPort.of(1), result);
}
项目:floodlight-hardware    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)).andReturn(true).anyTimes();
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));

    removeDeviceFromContext();
}
项目:floodlight-hardware    文件:ForwardingTest.java   
@Test
public void testForwardNoPathIPv6() throws Exception {
    learnDevicesIPv6(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD))
    .andReturn(true).anyTimes();
    // Reset XID to expected (dependent on prior unit tests)
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetInIPv6, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFloodedIPv6));

    removeDeviceFromContext();
}
项目:floodlight-hardware    文件:HubTest.java   
@Test
public void testFloodNoBufferId() throws Exception {
    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();

    // build our expected flooded packetOut
    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setBufferId(OFBufferId.NO_BUFFER)
        .setXid(1)
        .setInPort(OFPort.of(1))
        .setData(this.testPacketSerialized).build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertTrue(OFMessageUtils.equalsIgnoreXid(m, po));
}
项目:floodlight-hardware    文件:HubTest.java   
@Test
public void testFloodBufferId() throws Exception {
    MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
    this.packetIn = this.packetIn.createBuilder()
            .setBufferId(OFBufferId.of(10))
            .setXid(1)
            .build();

    OFActionOutput ao = OFFactories.getFactory(OFVersion.OF_13).actions().buildOutput().setPort(OFPort.FLOOD).build();
    List<OFAction> al = new ArrayList<OFAction>();
    al.add(ao);
    // build our expected flooded packetOut
    OFPacketOut po = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
        .setActions(al)
        .setXid(1)
        .setBufferId(OFBufferId.of(10))
        .setInPort(OFPort.of(1))
        .build();

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    EasyMock.expect(mockSwitch.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
    Capture<OFPacketOut> wc1 = new Capture<OFPacketOut>(CaptureType.ALL);
    expect(mockSwitch.write(capture(wc1))).andReturn(true).anyTimes();

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(
            OFType.PACKET_IN).get(0);
    listener.receive(mockSwitch, this.packetIn,
                     parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    OFMessage m = wc1.getValue();
    assertEquals(po, m);
}
项目:floodlight-hardware    文件:LearningSwitchTest.java   
@Test
public void testFlood() throws Exception {
    // build our expected flooded packetOut
    OFPacketOut po = factory.buildPacketOut()
        .setInPort(OFPort.of(1))
        .setActions(Arrays.asList((OFAction)factory.actions().output(OFPort.FLOOD, 0xffFFffFF)))
        .setBufferId(OFBufferId.NO_BUFFER)
        .setData(this.testPacketSerialized)
     .build();

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    // Mock up our expected behavior
    IOFSwitch mockSwitch = createMock(IOFSwitch.class);
    expect(mockSwitch.getId()).andReturn(DatapathId.of("00:11:22:33:44:55:66:77")).anyTimes();
    expect(mockSwitch.getOFFactory()).andReturn(factory).anyTimes();
    expect(mockSwitch.write(EasyMock.capture(wc1))).andReturn(true).once(); // expect po

    // Start recording the replay on the mocks
    replay(mockSwitch);
    // Get the listener and trigger the packet in
    IOFMessageListener listener = mockFloodlightProvider.getListeners().get(OFType.PACKET_IN).get(0);
    // Make sure it's the right listener
    listener.receive(mockSwitch, this.packetIn, parseAndAnnotate(this.packetIn));

    // Verify the replay matched our expectations
    OFPort result = learningSwitch.getFromPortMap(mockSwitch, MacAddress.of("00:44:33:22:11:00"), VlanVid.ofVlan(42));
    verify(mockSwitch);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), po));

    // Verify the MAC table inside the switch
    assertEquals(OFPort.of(1), result);
}
项目:ACAMPController    文件:ForwardingTest.java   
@Test
public void testForwardNoPath() throws Exception {
    learnDevices(DestDeviceToLearn.NONE);

    // Set no destination attachment point or route
    // expect no Flow-mod but expect the packet to be flooded

    Capture<OFMessage> wc1 = new Capture<OFMessage>(CaptureType.ALL);

    Set<OFPort> bcastPorts = new HashSet<OFPort>();
    bcastPorts.add(OFPort.of(10));

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getSwitchBroadcastPorts(DatapathId.of(1L))).andReturn(bcastPorts).once();
    expect(topology.isAttachmentPointPort(DatapathId.of(anyLong()),
            OFPort.of(anyShort())))
            .andReturn(true)
            .anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)).andReturn(true).anyTimes();
    expect(sw1.write(capture(wc1))).andReturn(true).once();
    replay(sw1, sw2, routingEngine, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine);

    assertTrue(wc1.hasCaptured());
    assertTrue(OFMessageUtils.equalsIgnoreXid(wc1.getValue(), packetOutFlooded));

    removeDeviceFromContext();
}