Java 类org.projectfloodlight.openflow.protocol.OFPacketOut 实例源码

项目:open-kilda    文件:PathVerificationService.java   
@Override
public boolean sendDiscoveryMessage(DatapathId srcSwId, OFPort port, DatapathId dstSwId) {
    IOFSwitch srcSwitch = switchService.getSwitch(srcSwId);

    if (srcSwitch == null) { // fix dereference violations in case race conditions
        return false;
    }

    if (dstSwId == null) {
        return srcSwitch.write(generateVerificationPacket(srcSwitch, port));
    }
    IOFSwitch dstSwitch = switchService.getSwitch(dstSwId);
    OFPacketOut ofPacketOut = generateVerificationPacket(srcSwitch, port, dstSwitch);
    logger.debug("sending verification packet out {}/{}: {}", srcSwitch.getId().toString(), port.getPortNumber(),
            Hex.encodeHexString(ofPacketOut.getData()));
    return srcSwitch.write(ofPacketOut);
}
项目:open-kilda    文件:PathTest.java   
@Test
    public void testCreate() {
        OFPacketOut packetOut = pvs.generateVerificationPacket(sw1, sw1Port1.getPortNo());

        expect(packetIn.getData()).andReturn(packetOut.getData());
        expect(packetIn.getInPort()).andReturn(sw2Port1.getPortNo());
        replay(packetIn);

        byte[] d = packetIn.getData();
        System.out.println(packetOut.toString());
        System.out.println(Hex.encodeHexString(packetOut.getData()));
        System.out.println(Hex.encodeHexString(d));

//    Path path = new Path(sw2, sw2Port1.getPortNo(), verPacket);
//    assertTrue(path.getSource().equals(sw1Port1));
//    assertTrue(path.getDestination().equals(sw2Port1));
//    assertEquals(path.getLatency(), 100);
    }
项目:open-kilda    文件:PathVerificationPacketOutTest.java   
@SuppressWarnings("static-access")
@Test
public void testBcastPacket() {
    // This is Broadcast so set dstIpTarget to the broadcast IP
    InetSocketAddress dstIpTarget = new InetSocketAddress(pvs.VERIFICATION_PACKET_IP_DST, 200);

    // Generate the VerificationPacket
    OFPacketOut packet = pvs.generateVerificationPacket(sw1, OFPort.of(1));
    System.out.println("packet: " + Hex.encodeHexString(packet.getData()));

    // Source MAC will always be that of sw1 for both Unicast and Broadcast
    byte[] srcMac = Arrays.copyOfRange(packet.getData(), 6, 12);
    assertArrayEquals(MacAddress.of(sw1HwAddrTarget).getBytes(), srcMac);

    // Destination MAC should be that of BROADCAST for Broadcast Packet
    byte[] dstMac = Arrays.copyOfRange(packet.getData(), 0, 6);
    assertArrayEquals(MacAddress.of(pvs.VERIFICATION_BCAST_PACKET_DST).getBytes(), dstMac);

    // Source IP is actual switch1 IP
    byte[] srcIpActual = Arrays.copyOfRange(packet.getData(), 26, 30);
    assertArrayEquals(srcIpTarget.getAddress().getAddress(), srcIpActual);

    // Destination IP is that of DESTINATION BROADCAST IP
    byte[] dstIpActual = Arrays.copyOfRange(packet.getData(), 30, 34);
    assertArrayEquals(dstIpTarget.getAddress().getAddress(), dstIpActual);
}
项目:open-kilda    文件:PathVerificationPacketOutTest.java   
@Test
public void testUncastPacket() {
    // Generate the VerificationPacket
    OFPacketOut packet = pvs.generateVerificationPacket(sw1, OFPort.of(1), sw2);

    // Source MAC will always be that of sw1 for both Unicast and Broadcast
    byte[] srcMacActual = Arrays.copyOfRange(packet.getData(), 6, 12);
    assertArrayEquals(MacAddress.of(sw1HwAddrTarget).getBytes(), srcMacActual);

    // Destination MAC should be that of sw2 for Unicast Packet
    byte[] dstMacActual = Arrays.copyOfRange(packet.getData(), 0, 6);
    assertArrayEquals(MacAddress.of(sw2HwAddrTarget).getBytes(), dstMacActual);

    // Source and Destination IP's are the respective switch IP's
    byte[] srcIpActual = Arrays.copyOfRange(packet.getData(), 26, 30);
    assertArrayEquals(srcIpTarget.getAddress().getAddress(), srcIpActual);
    byte[] dstIpActual = Arrays.copyOfRange(packet.getData(), 30, 34);
    assertArrayEquals(dstIpTarget.getAddress().getAddress(), dstIpActual);
}
项目:fresco_floodlight    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}
项目:fresco_floodlight    文件:LinkDiscoveryManager.java   
/**
 * Send link discovery message out of a given switch port. The discovery
 * message may be a standard LLDP or a modified LLDP, where the dst mac
 * address is set to :ff. TODO: The modified LLDP will updated in the future
 * and may use a different eth-type.
 *
 * @param sw
 * @param port
 * @param isStandard
 *            indicates standard or modified LLDP
 * @param isReverse
 *            indicates whether the LLDP was sent as a response
 */
protected void sendDiscoveryMessage(DatapathId sw, OFPort port,
        boolean isStandard, boolean isReverse) {

    // Takes care of all checks including null pointer checks.
    if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse))
        return;

    IOFSwitch iofSwitch = switchService.getSwitch(sw);
    if (iofSwitch == null)             //fix dereference violations in case race conditions
        return;
    OFPortDesc ofpPort = iofSwitch.getPort(port);

    OFPacketOut po = generateLLDPMessage(iofSwitch, port, isStandard, isReverse);
    OFPacketOut.Builder pob = po.createBuilder();

    // Add actions
    List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort.getPortNo());
    pob.setActions(actions);

    // no need to set length anymore

    // send
    // no more try-catch. switch will silently fail
    iofSwitch.write(pob.build());
}
项目:fresco_floodlight    文件:OFConnectionTest.java   
/** write a packetOut, which is not buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    eventLoop.runTasks();
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:fresco_floodlight    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));
    eventLoop.runTasks();
    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:iTAP-controller    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}
项目:iTAP-controller    文件:LearningSwitch.java   
/**
 * Writes an OFPacketOut message to a switch.
 * @param sw The switch to write the PacketOut to.
 * @param packetInMessage The corresponding PacketIn.
 * @param egressPort The switchport to output the PacketOut.
 */
private void writePacketOutForPacketIn(IOFSwitch sw, OFPacketIn packetInMessage, OFPort egressPort) {
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();

    // Set buffer_id, in_port, actions_len
    pob.setBufferId(packetInMessage.getBufferId());
    pob.setInPort(packetInMessage.getVersion().compareTo(OFVersion.OF_12) < 0 ? packetInMessage.getInPort() : packetInMessage.getMatch().get(MatchField.IN_PORT));

    // set actions
    List<OFAction> actions = new ArrayList<OFAction>(1);
    actions.add(sw.getOFFactory().actions().buildOutput().setPort(egressPort).setMaxLen(0xffFFffFF).build());
    pob.setActions(actions);

    // set data - only if buffer_id == -1
    if (packetInMessage.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = packetInMessage.getData();
        pob.setData(packetData);
    }

    // and write it out
    counterPacketOut.increment();
    sw.write(pob.build());

}
项目:iTAP-controller    文件:OFConnectionTest.java   
/** write a packetOut, which is buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:iTAP-controller    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));

    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:SDN-Multicast    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}
项目:SDN-Multicast    文件:LinkDiscoveryManager.java   
/**
 * Send link discovery message out of a given switch port. The discovery
 * message may be a standard LLDP or a modified LLDP, where the dst mac
 * address is set to :ff. TODO: The modified LLDP will updated in the future
 * and may use a different eth-type.
 *
 * @param sw
 * @param port
 * @param isStandard
 *            indicates standard or modified LLDP
 * @param isReverse
 *            indicates whether the LLDP was sent as a response
 */
protected void sendDiscoveryMessage(DatapathId sw, OFPort port,
        boolean isStandard, boolean isReverse) {

    // Takes care of all checks including null pointer checks.
    if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse))
        return;

    IOFSwitch iofSwitch = switchService.getSwitch(sw);
    if (iofSwitch == null)             //fix dereference violations in case race conditions
        return;
    OFPortDesc ofpPort = iofSwitch.getPort(port);

    OFPacketOut po = generateLLDPMessage(iofSwitch, port, isStandard, isReverse);
    OFPacketOut.Builder pob = po.createBuilder();

    // Add actions
    List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort.getPortNo());
    pob.setActions(actions);

    // no need to set length anymore

    // send
    // no more try-catch. switch will silently fail
    iofSwitch.write(pob.build());
}
项目:SDN-Multicast    文件:OFConnectionTest.java   
/** write a packetOut, which is not buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    eventLoop.runTasks();
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:SDN-Multicast    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));
    eventLoop.runTasks();
    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:arscheduler    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}
项目:arscheduler    文件:LinkDiscoveryManager.java   
/**
 * Send link discovery message out of a given switch port. The discovery
 * message may be a standard LLDP or a modified LLDP, where the dst mac
 * address is set to :ff. TODO: The modified LLDP will updated in the future
 * and may use a different eth-type.
 *
 * @param sw
 * @param port
 * @param isStandard
 *            indicates standard or modified LLDP
 * @param isReverse
 *            indicates whether the LLDP was sent as a response
 */
protected void sendDiscoveryMessage(DatapathId sw, OFPort port,
        boolean isStandard, boolean isReverse) {

    // Takes care of all checks including null pointer checks.
    if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse))
        return;

    IOFSwitch iofSwitch = switchService.getSwitch(sw);
    if (iofSwitch == null)             //fix dereference violations in case race conditions
        return;
    OFPortDesc ofpPort = iofSwitch.getPort(port);

    OFPacketOut po = generateLLDPMessage(iofSwitch, port, isStandard, isReverse);
    OFPacketOut.Builder pob = po.createBuilder();

    // Add actions
    List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort.getPortNo());
    pob.setActions(actions);

    // no need to set length anymore

    // send
    // no more try-catch. switch will silently fail
    iofSwitch.write(pob.build());
}
项目:arscheduler    文件:OFConnectionTest.java   
/** write a packetOut, which is not buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    eventLoop.runTasks();
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:arscheduler    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));
    eventLoop.runTasks();
    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:floodlight1.2-delay    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}
项目:floodlight1.2-delay    文件:LinkDiscoveryManager.java   
/**
 * Send link discovery message out of a given switch port. The discovery
 * message may be a standard LLDP or a modified LLDP, where the dst mac
 * address is set to :ff. TODO: The modified LLDP will updated in the future
 * and may use a different eth-type.
 *
 * @param sw
 * @param port
 * @param isStandard
 *            indicates standard or modified LLDP
 * @param isReverse
 *            indicates whether the LLDP was sent as a response
 */
protected void sendDiscoveryMessage(DatapathId sw, OFPort port,
        boolean isStandard, boolean isReverse) {

    // Takes care of all checks including null pointer checks.
    if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse))
        return;

    IOFSwitch iofSwitch = switchService.getSwitch(sw);
    if (iofSwitch == null)             //fix dereference violations in case race conditions
        return;
    OFPortDesc ofpPort = iofSwitch.getPort(port);

    OFPacketOut po = generateLLDPMessage(iofSwitch, port, isStandard, isReverse);
    OFPacketOut.Builder pob = po.createBuilder();

    // Add actions
    List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort.getPortNo());
    pob.setActions(actions);

    // no need to set length anymore

    // send
    // no more try-catch. switch will silently fail
    iofSwitch.write(pob.build());
}
项目:floodlight1.2-delay    文件:OFConnectionTest.java   
/** write a packetOut, which is not buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    eventLoop.runTasks();
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:floodlight1.2-delay    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));
    eventLoop.runTasks();
    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:floodlight-hardware    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();
}
项目:floodlight-hardware    文件:LinkDiscoveryManager.java   
/**
 * Send link discovery message out of a given switch port. The discovery
 * message may be a standard LLDP or a modified LLDP, where the dst mac
 * address is set to :ff. TODO: The modified LLDP will updated in the future
 * and may use a different eth-type.
 *
 * @param sw
 * @param port
 * @param isStandard
 *            indicates standard or modified LLDP
 * @param isReverse
 *            indicates whether the LLDP was sent as a response
 */
protected void sendDiscoveryMessage(DatapathId sw, OFPort port,
        boolean isStandard, boolean isReverse) {

    // Takes care of all checks including null pointer checks.
    if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse))
        return;

    IOFSwitch iofSwitch = switchService.getSwitch(sw);
    if (iofSwitch == null)             //fix dereference violations in case race conditions
        return;
    OFPortDesc ofpPort = iofSwitch.getPort(port);

    OFPacketOut po = generateLLDPMessage(iofSwitch, port, isStandard, isReverse);
    OFPacketOut.Builder pob = po.createBuilder();

    // Add actions
    List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort.getPortNo());
    pob.setActions(actions);

    // no need to set length anymore

    // send
    // no more try-catch. switch will silently fail
    iofSwitch.write(pob.build());
}
项目:floodlight-hardware    文件:OFConnectionTest.java   
/** write a packetOut, which is not buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    eventLoop.runTasks();
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:floodlight-hardware    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));
    eventLoop.runTasks();
    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:ACAMPController    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}
项目:ACAMPController    文件:LinkDiscoveryManager.java   
/**
 * Send link discovery message out of a given switch port. The discovery
 * message may be a standard LLDP or a modified LLDP, where the dst mac
 * address is set to :ff. TODO: The modified LLDP will updated in the future
 * and may use a different eth-type.
 *
 * @param sw
 * @param port
 * @param isStandard
 *            indicates standard or modified LLDP
 * @param isReverse
 *            indicates whether the LLDP was sent as a response
 */
protected void sendDiscoveryMessage(DatapathId sw, OFPort port,
        boolean isStandard, boolean isReverse) {

    // Takes care of all checks including null pointer checks.
    if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse))
        return;

    IOFSwitch iofSwitch = switchService.getSwitch(sw);
    if (iofSwitch == null)             //fix dereference violations in case race conditions
        return;
    OFPortDesc ofpPort = iofSwitch.getPort(port);

    OFPacketOut po = generateLLDPMessage(iofSwitch, port, isStandard, isReverse);
    OFPacketOut.Builder pob = po.createBuilder();

    // Add actions
    List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort.getPortNo());
    pob.setActions(actions);

    // no need to set length anymore

    // send
    // no more try-catch. switch will silently fail
    iofSwitch.write(pob.build());
}
项目:ACAMPController    文件:OFConnectionTest.java   
/** write a packetOut, which is not buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    eventLoop.runTasks();
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:ACAMPController    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));
    eventLoop.runTasks();
    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:fast-failover-demo    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}
项目:fast-failover-demo    文件:LearningSwitch.java   
/**
 * Writes an OFPacketOut message to a switch.
 * @param sw The switch to write the PacketOut to.
 * @param packetInMessage The corresponding PacketIn.
 * @param egressPort The switchport to output the PacketOut.
 */
private void writePacketOutForPacketIn(IOFSwitch sw, OFPacketIn packetInMessage, OFPort egressPort) {
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();

    // Set buffer_id, in_port, actions_len
    pob.setBufferId(packetInMessage.getBufferId());
    pob.setInPort(packetInMessage.getVersion().compareTo(OFVersion.OF_12) < 0 ? packetInMessage.getInPort() : packetInMessage.getMatch().get(MatchField.IN_PORT));

    // set actions
    List<OFAction> actions = new ArrayList<OFAction>(1);
    actions.add(sw.getOFFactory().actions().buildOutput().setPort(egressPort).setMaxLen(0xffFFffFF).build());
    pob.setActions(actions);

    // set data - only if buffer_id == -1
    if (packetInMessage.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = packetInMessage.getData();
        pob.setData(packetData);
    }

    // and write it out
    counterPacketOut.increment();
    sw.write(pob.build());

}
项目:fast-failover-demo    文件:OFConnectionTest.java   
/** write a packetOut, which is buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(packetOut);
    assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));

    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(packetOut));
}
项目:fast-failover-demo    文件:OFConnectionTest.java   
/** write a list of messages */
@Test(timeout = 5000)
public void testMessageWriteList() throws InterruptedException, ExecutionException {
    Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();

    OFHello hello = factory.hello(ImmutableList.<OFHelloElem>of());
    OFPacketOut packetOut = factory.buildPacketOut()
            .setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
            .setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
            .build();

    conn.write(ImmutableList.of(hello, packetOut));

    assertThat("Write should have been written", cMsgList.hasCaptured(), equalTo(true));
    List<OFMessage> value = cMsgList.getValue();
    logger.info("Captured channel write: "+value);
    assertThat("Should have captured MsgList", cMsgList.getValue(),
            Matchers.<OFMessage> contains(hello, packetOut));
}
项目:ravikumaran201504    文件:LinkDiscovery.java   
/**
 * Add physical port port to discovery process.
 * Send out initial LLDP and label it as slow port.
 *
 * @param port the port
 */
public void addPort(final OFPortDesc port) {
    // Ignore ports that are not on this switch, or already booted. */
    this.ports.put(port.getPortNo().getPortNumber(), port);
    synchronized (this) {
        this.log.debug("sending init probe to port {}",
                port.getPortNo().getPortNumber());
        OFPacketOut pkt;

        pkt = this.createLLDPPacketOut(port);
        this.sw.sendMsg(pkt);
        if (useBDDP) {
            OFPacketOut bpkt = this.createBDDPPacketOut(port);
            this.sw.sendMsg(bpkt);
        }

        this.slowPorts.add(port.getPortNo().getPortNumber());
    }

}
项目:ravikumaran201504    文件:LinkDiscovery.java   
/**
 * Creates packet_out LLDP for specified output port.
 *
 * @param port the port
 * @return Packet_out message with LLDP data
 */
private OFPacketOut createLLDPPacketOut(final OFPortDesc port) {
    if (port == null) {
        return null;
    }
    OFPacketOut.Builder packetOut = this.ofFactory.buildPacketOut();
    packetOut.setBufferId(OFBufferId.NO_BUFFER);
    OFAction act = this.ofFactory.actions().buildOutput()
            .setPort(port.getPortNo()).build();
    packetOut.setActions(Collections.singletonList(act));
    this.lldpPacket.setPort(port.getPortNo().getPortNumber());
    this.ethPacket.setSourceMACAddress(port.getHwAddr().getBytes());

    final byte[] lldp = this.ethPacket.serialize();
    packetOut.setData(lldp);
    return packetOut.build();
}
项目:ravikumaran201504    文件:LinkDiscovery.java   
/**
 * Creates packet_out BDDP for specified output port.
 *
 * @param port the port
 * @return Packet_out message with LLDP data
 */
private OFPacketOut createBDDPPacketOut(final OFPortDesc port) {
    if (port == null) {
        return null;
    }
    OFPacketOut.Builder packetOut = sw.factory().buildPacketOut();

    packetOut.setBufferId(OFBufferId.NO_BUFFER);

    OFActionOutput.Builder act = sw.factory().actions().buildOutput()
            .setPort(port.getPortNo());
    OFAction out = act.build();
    packetOut.setActions(Collections.singletonList(out));
    this.lldpPacket.setPort(port.getPortNo().getPortNumber());
    this.bddpEth.setSourceMACAddress(port.getHwAddr().getBytes());

    final byte[] bddp = this.bddpEth.serialize();
    packetOut.setData(bddp);

    return packetOut.build();
}
项目:floodlightLB    文件:Hub.java   
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
    pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));

    // set actions
    OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
    actionBuilder.setPort(OFPort.FLOOD);
    pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));

    // set data if it is included in the packetin
    if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
        byte[] packetData = pi.getData();
        pob.setData(packetData);
    }
    return pob.build();  
}