当前位置: 首页>>代码示例>>Java>>正文


Java OFPacketOut.setActionsLength方法代码示例

本文整理汇总了Java中org.openflow.protocol.OFPacketOut.setActionsLength方法的典型用法代码示例。如果您正苦于以下问题:Java OFPacketOut.setActionsLength方法的具体用法?Java OFPacketOut.setActionsLength怎么用?Java OFPacketOut.setActionsLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openflow.protocol.OFPacketOut的用法示例。


在下文中一共展示了OFPacketOut.setActionsLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receive

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory()
            .getMessage(OFType.PACKET_OUT);
    po.setBufferId(pi.getBufferId())
        .setInPort(pi.getInPort());

    // set actions
    OFActionOutput action = new OFActionOutput()
        .setPort(OFPort.OFPP_FLOOD.getValue());
    po.setActions(Collections.singletonList((OFAction)action));
    po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);

    // set data if is is included in the packetin
    if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
        byte[] packetData = pi.getPacketData();
        po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
                + po.getActionsLength() + packetData.length));
        po.setPacketData(packetData);
    } else {
        po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
                + po.getActionsLength()));
    }
    try {
        sw.write(po, cntx);
    } catch (IOException e) {
        log.error("Failure writing PacketOut", e);
    }

    return Command.CONTINUE;
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:32,代码来源:Hub.java

示例2: receive

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
    OFPacketIn pi = (OFPacketIn) msg;
    OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory()
            .getMessage(OFType.PACKET_OUT);
    po.setBufferId(pi.getBufferId())
        .setInPort(pi.getInPort());

    // set actions
    OFActionOutput action = new OFActionOutput()
        .setPort((short) OFPort.OFPP_FLOOD.getValue());
    po.setActions(Collections.singletonList((OFAction)action));
    po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);

    // set data if is is included in the packetin
    if (pi.getBufferId() == 0xffffffff) {
        byte[] packetData = pi.getPacketData();
        po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
                + po.getActionsLength() + packetData.length));
        po.setPacketData(packetData);
    } else {
        po.setLength(U16.t(OFPacketOut.MINIMUM_LENGTH
                + po.getActionsLength()));
    }
    try {
        sw.write(po, cntx);
    } catch (IOException e) {
        log.error("Failure writing PacketOut", e);
    }

    return Command.CONTINUE;
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:32,代码来源:Hub.java

示例3: createBDDPPacketOut

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * Creates packet_out LLDP for specified output port.
 *
 * @param port the port
 * @return Packet_out message with LLDP data
 * @throws PortMappingException
 */
private OFPacketOut createBDDPPacketOut(final PhysicalPort port)
        throws PortMappingException {
    if (port == null) {
        throw new PortMappingException(
                "Cannot send LLDP associated with a nonexistent port");
    }
    final OFPacketOut packetOut = (OFPacketOut) this.ovxMessageFactory
            .getMessage(OFType.PACKET_OUT);
    packetOut.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    final List<OFAction> actionsList = new LinkedList<OFAction>();
    final OFActionOutput out = (OFActionOutput) this.ovxMessageFactory
            .getAction(OFActionType.OUTPUT);
    out.setPort(port.getPortNumber());
    actionsList.add(out);
    packetOut.setActions(actionsList);
    final short alen = SwitchDiscoveryManager.countActionsLen(actionsList);
    this.lldpPacket.setPort(port);
    this.bddpEth.setSourceMACAddress(port.getHardwareAddress());

    final byte[] bddp = this.bddpEth.serialize();
    packetOut.setActionsLength(alen);
    packetOut.setPacketData(bddp);
    packetOut
            .setLength((short) (OFPacketOut.MINIMUM_LENGTH + alen + bddp.length));
    return packetOut;
}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:34,代码来源:SwitchDiscoveryManager.java

示例4: doFlood

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * Creates a OFPacketOut with the OFPacketIn data that is flooded on all ports unless
 * the port is blocked, in which case the packet will be dropped.
 * @param sw The switch that receives the OFPacketIn
 * @param pi The OFPacketIn that came to the switch
 * @param cntx The FloodlightContext associated with this OFPacketIn
 */
@LogMessageDoc(level="ERROR",
               message="Failure writing PacketOut " +
               		"switch={switch} packet-in={packet-in} " +
               		"packet-out={packet-out}",
               explanation="An I/O error occured while writing a packet " +
               		"out message to the switch",
               recommendation=LogMessageDoc.CHECK_SWITCH)
protected void doFlood(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
    if (topology.isIncomingBroadcastAllowed(sw.getId(),
                                            pi.getInPort()) == false) {
        if (log.isTraceEnabled()) {
            log.trace("doFlood, drop broadcast packet, pi={}, " +
                      "from a blocked port, srcSwitch=[{},{}], linkInfo={}",
                      new Object[] {pi, sw.getId(),pi.getInPort()});
        }
        return;
    }

    // Set Action to flood
    OFPacketOut po =
        (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
    List<OFAction> actions = new ArrayList<OFAction>();
    if (sw.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)) {
        actions.add(new OFActionOutput(OFPort.OFPP_FLOOD.getValue(),
                                       (short)0xFFFF));
    } else {
        actions.add(new OFActionOutput(OFPort.OFPP_ALL.getValue(),
                                       (short)0xFFFF));
    }
    po.setActions(actions);
    po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);

    // set buffer-id, in-port and packet-data based on packet-in
    short poLength = (short)(po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH);
    po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    po.setInPort(pi.getInPort());
    byte[] packetData = pi.getPacketData();
    poLength += packetData.length;
    po.setPacketData(packetData);
    po.setLength(poLength);

    try {
        if (log.isTraceEnabled()) {
            log.trace("Writing flood PacketOut switch={} packet-in={} packet-out={}",
                      new Object[] {sw, pi, po});
        }
        messageDamper.write(sw, po, cntx);
    } catch (IOException e) {
        log.error("Failure writing PacketOut switch={} packet-in={} packet-out={}",
                new Object[] {sw, pi, po}, e);
    }

    return;
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:62,代码来源:Forwarding.java

示例5: packetOutMultiPort

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * Write packetout message to sw with output actions to one or more
 * output ports with inPort/outPorts passed in.
 * @param packetData
 * @param sw
 * @param inPort
 * @param ports
 * @param cntx
 */
public void packetOutMultiPort(byte[] packetData,
                               IOFSwitch sw,
                               short inPort,
                               Set<Integer> outPorts,
                               FloodlightContext cntx) {
    //setting actions
    List<OFAction> actions = new ArrayList<OFAction>();

    Iterator<Integer> j = outPorts.iterator();

    while (j.hasNext())
    {
        actions.add(new OFActionOutput(j.next().shortValue(),
                                       (short) 0));
    }

    OFPacketOut po =
            (OFPacketOut) floodlightProvider.getOFMessageFactory().
            getMessage(OFType.PACKET_OUT);
    po.setActions(actions);
    po.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH *
            outPorts.size()));

    // set buffer-id to BUFFER_ID_NONE, and set in-port to OFPP_NONE
    po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    po.setInPort(inPort);

    // data (note buffer_id is always BUFFER_ID_NONE) and length
    short poLength = (short)(po.getActionsLength() +
            OFPacketOut.MINIMUM_LENGTH);
    poLength += packetData.length;
    po.setPacketData(packetData);
    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, po);
        if (log.isTraceEnabled()) {
            log.trace("write broadcast packet on switch-id={} " +
                    "interfaces={} packet-out={}",
                    new Object[] {sw.getId(), outPorts, po});
        }
        messageDamper.write(sw, po, cntx);

    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:57,代码来源:ForwardingBase.java

示例6: writePacketOutForPacketIn

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * 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,
                                      short egressPort) {
    // from openflow 1.0 spec - need to set these on a struct ofp_packet_out:
    // uint32_t buffer_id; /* ID assigned by datapath (-1 if none). */
    // uint16_t in_port; /* Packet's input port (OFPP_NONE if none). */
    // uint16_t actions_len; /* Size of action array in bytes. */
    // struct ofp_action_header actions[0]; /* Actions. */
    /* uint8_t data[0]; */ /* Packet data. The length is inferred
                              from the length field in the header.
                              (Only meaningful if buffer_id == -1.) */

    OFPacketOut packetOutMessage = (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
    short packetOutLength = (short)OFPacketOut.MINIMUM_LENGTH; // starting length

    // Set buffer_id, in_port, actions_len
    packetOutMessage.setBufferId(packetInMessage.getBufferId());
    packetOutMessage.setInPort(packetInMessage.getInPort());
    packetOutMessage.setActionsLength((short)OFActionOutput.MINIMUM_LENGTH);
    packetOutLength += OFActionOutput.MINIMUM_LENGTH;

    // set actions
    List<OFAction> actions = new ArrayList<OFAction>(1);
    actions.add(new OFActionOutput(egressPort, (short) 0));
    packetOutMessage.setActions(actions);

    // set data - only if buffer_id == -1
    if (packetInMessage.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
        byte[] packetData = packetInMessage.getPacketData();
        packetOutMessage.setPacketData(packetData);
        packetOutLength += (short)packetData.length;
    }

    // finally, set the total length
    packetOutMessage.setLength(packetOutLength);

    // and write it out
    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, packetOutMessage);
        sw.write(packetOutMessage, null);
    } catch (IOException e) {
        log.error("Failed to write {} to switch {}: {}", new Object[]{ packetOutMessage, sw, e });
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:51,代码来源:LearningSwitch.java

示例7: sendDiscoveryMessage

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * 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
 */
@LogMessageDoc(level = "ERROR",
               message = "Failure sending LLDP out port {port} on switch {switch}",
               explanation = "An I/O error occured while sending LLDP message "
                             + "to the switch.",
               recommendation = LogMessageDoc.CHECK_SWITCH)
protected void sendDiscoveryMessage(long sw, short port,
                                    boolean isStandard, boolean isReverse) {

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

    IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw);
    OFPhysicalPort ofpPort = iofSwitch.getPort(port).toOFPhysicalPort();

    if (log.isTraceEnabled()) {
        log.trace("Sending LLDP packet out of swich: {}, port: {}",
                  HexString.toHexString(sw), port);
    }
    OFPacketOut po = generateLLDPMessage(sw, port, isStandard, isReverse);

    // Add actions
    List<OFAction> actions = getDiscoveryActions(iofSwitch, ofpPort);
    po.setActions(actions);
    short  actionLength = 0;
    Iterator <OFAction> actionIter = actions.iterator();
    while (actionIter.hasNext()) {
        actionLength += actionIter.next().getLength();
    }
    po.setActionsLength(actionLength);

    // po already has the minimum length + data length set
    // simply add the actions length to this.
    po.setLengthU(po.getLengthU() + po.getActionsLength());

    // send
    try {
        iofSwitch.write(po, null);
        iofSwitch.flush();
    } catch (IOException e) {
        log.error("Failure sending LLDP out port {} on switch {}",
                  new Object[] { port, iofSwitch.getStringId() }, e);
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:58,代码来源:LinkDiscoveryManager.java

示例8: doMultiActionPacketOut

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * TODO This method must be moved to a layer below forwarding
 * so that anyone can use it.
 * @param packetData
 * @param sw
 * @param ports
 * @param cntx
 */
@LogMessageDoc(level="ERROR",
        message="Failed to clear all flows on switch {switch}",
        explanation="An I/O error occured while trying send " +
        		"topology discovery packet",
        recommendation=LogMessageDoc.CHECK_SWITCH)
public void doMultiActionPacketOut(byte[] packetData, IOFSwitch sw,
                                   Set<Short> ports,
                                   FloodlightContext cntx) {

    if (ports == null) return;
    if (packetData == null || packetData.length <= 0) return;

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

    List<OFAction> actions = new ArrayList<OFAction>();
    for(short p: ports) {
        actions.add(new OFActionOutput(p, (short) 0));
    }

    // set actions
    po.setActions(actions);
    // set action length
    po.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH *
            ports.size()));
    // set buffer-id to BUFFER_ID_NONE
    po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    // set in-port to OFPP_NONE
    po.setInPort(OFPort.OFPP_NONE.getValue());

    // set packet data
    po.setPacketData(packetData);

    // compute and set packet length.
    short poLength = (short)(OFPacketOut.MINIMUM_LENGTH +
            po.getActionsLength() +
            packetData.length);

    po.setLength(poLength);

    try {
        //counterStore.updatePktOutFMCounterStore(sw, po);
        if (log.isTraceEnabled()) {
            log.trace("write broadcast packet on switch-id={} " +
                    "interaces={} packet-data={} packet-out={}",
                    new Object[] {sw.getId(), ports, packetData, po});
        }
        sw.write(po, cntx);

    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:63,代码来源:TopologyManager.java

示例9: packetOutMultiPort

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * Write packetout message to sw with output actions to one or more
 * output ports with inPort/outPorts passed in.
 * @param packetData
 * @param sw
 * @param inPort
 * @param ports
 * @param cntx
 */
public void packetOutMultiPort(byte[] packetData,
                               IOFSwitch sw,
                               short inPort,
                               Set<Integer> outPorts,
                               FloodlightContext cntx) {
    //setting actions
    List<OFAction> actions = new ArrayList<OFAction>();

    Iterator<Integer> j = outPorts.iterator();

    while (j.hasNext())
    {
        actions.add(new OFActionOutput(j.next().shortValue(), 
                                       (short) 0));
    }

    OFPacketOut po = 
            (OFPacketOut) floodlightProvider.getOFMessageFactory().
            getMessage(OFType.PACKET_OUT);
    po.setActions(actions);
    po.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH * 
            outPorts.size()));

    // set buffer-id to BUFFER_ID_NONE, and set in-port to OFPP_NONE
    po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    po.setInPort(inPort);

    // data (note buffer_id is always BUFFER_ID_NONE) and length
    short poLength = (short)(po.getActionsLength() + 
            OFPacketOut.MINIMUM_LENGTH);
    poLength += packetData.length;
    po.setPacketData(packetData);
    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStore(sw, po);
        if (log.isTraceEnabled()) {
            log.trace("write broadcast packet on switch-id={} " + 
                    "interfaces={} packet-out={}",
                    new Object[] {sw.getId(), outPorts, po});
        }
        messageDamper.write(sw, po, cntx);

    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:57,代码来源:ForwardingBase.java

示例10: writePacketOutForPacketIn

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * 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, 
                                      short egressPort) {
    // from openflow 1.0 spec - need to set these on a struct ofp_packet_out:
    // uint32_t buffer_id; /* ID assigned by datapath (-1 if none). */
    // uint16_t in_port; /* Packet's input port (OFPP_NONE if none). */
    // uint16_t actions_len; /* Size of action array in bytes. */
    // struct ofp_action_header actions[0]; /* Actions. */
    /* uint8_t data[0]; */ /* Packet data. The length is inferred
                              from the length field in the header.
                              (Only meaningful if buffer_id == -1.) */
    
    OFPacketOut packetOutMessage = (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
    short packetOutLength = (short)OFPacketOut.MINIMUM_LENGTH; // starting length

    // Set buffer_id, in_port, actions_len
    packetOutMessage.setBufferId(packetInMessage.getBufferId());
    packetOutMessage.setInPort(packetInMessage.getInPort());
    packetOutMessage.setActionsLength((short)OFActionOutput.MINIMUM_LENGTH);
    packetOutLength += OFActionOutput.MINIMUM_LENGTH;
    
    // set actions
    List<OFAction> actions = new ArrayList<OFAction>(1);      
    actions.add(new OFActionOutput(egressPort, (short) 0));
    packetOutMessage.setActions(actions);

    // set data - only if buffer_id == -1
    if (packetInMessage.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
        byte[] packetData = packetInMessage.getPacketData();
        packetOutMessage.setPacketData(packetData); 
        packetOutLength += (short)packetData.length;
    }
    
    // finally, set the total length
    packetOutMessage.setLength(packetOutLength);              
        
    // and write it out
    try {
    	counterStore.updatePktOutFMCounterStore(sw, packetOutMessage);
        sw.write(packetOutMessage, null);
    } catch (IOException e) {
        log.error("Failed to write {} to switch {}: {}", new Object[]{ packetOutMessage, sw, e });
    }
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:51,代码来源:LearningSwitch.java

示例11: doMultiActionPacketOut

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/** 
 * TODO This method must be moved to a layer below forwarding
 * so that anyone can use it.
 * @param packetData
 * @param sw
 * @param ports
 * @param cntx
 */
@LogMessageDoc(level="ERROR",
        message="Failed to clear all flows on switch {switch}",
        explanation="An I/O error occured while trying send " +
        		"topology discovery packet",
        recommendation=LogMessageDoc.CHECK_SWITCH)
public void doMultiActionPacketOut(byte[] packetData, IOFSwitch sw, 
                                   Set<Short> ports,
                                   FloodlightContext cntx) {

    if (ports == null) return;
    if (packetData == null || packetData.length <= 0) return;

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

    List<OFAction> actions = new ArrayList<OFAction>();
    for(short p: ports) {
        actions.add(new OFActionOutput(p, (short) 0));
    }

    // set actions
    po.setActions(actions);
    // set action length
    po.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH * 
            ports.size()));
    // set buffer-id to BUFFER_ID_NONE
    po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    // set in-port to OFPP_NONE
    po.setInPort(OFPort.OFPP_NONE.getValue());

    // set packet data
    po.setPacketData(packetData);

    // compute and set packet length.
    short poLength = (short)(OFPacketOut.MINIMUM_LENGTH + 
            po.getActionsLength() + 
            packetData.length);

    po.setLength(poLength);

    try {
        //counterStore.updatePktOutFMCounterStore(sw, po);
        if (log.isTraceEnabled()) {
            log.trace("write broadcast packet on switch-id={} " + 
                    "interaces={} packet-data={} packet-out={}",
                    new Object[] {sw.getId(), ports, packetData, po});
        }
        sw.write(po, cntx);

    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:63,代码来源:TopologyManager.java

示例12: sendHostProbe

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
protected boolean sendHostProbe(InetAddress ip, MACAddress mac, long dpid, short port){
	byte[] data;
	
	//Currently, we use ICMPing to probe the host
	// data = generateARPPing(ip);
	data = generateICMPPing(ip, mac);
	
	IOFSwitch sw = floodlightProvider.getSwitch(dpid);
	
       if (sw == null) {
           return false;
       }
       ImmutablePort ofpPort = sw.getPort(port);

       if (ofpPort == null) {
           if (logger.isTraceEnabled()) {
               logger.trace("Null physical port. sw={}, port={}", sw, port);
           }
           return false;
       }

       OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
       po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
       po.setInPort(OFPort.OFPP_NONE);

       // set actions
       List<OFAction> actions = new ArrayList<OFAction>();
       actions.add(new OFActionOutput(port, (short) 0));
       po.setActions(actions);
       po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);

       // set data
       po.setLengthU(OFPacketOut.MINIMUM_LENGTH + po.getActionsLength() + data.length);
       po.setPacketData(data);

       // send
       try {
           sw.write(po, null);
           sw.flush();
       } catch (IOException e) {
           logger.error("Failure sending host probe out port {} on switch {}",
                     new Object[]{ port, sw.getStringId() }, e);
           return false;
       }
       return true;
       
}
 
开发者ID:xuraylei,项目名称:floodlight_with_topoguard,代码行数:48,代码来源:TopoloyUpdateChecker.java

示例13: doMultiActionPacketOut

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * TODO This method must be moved to a layer below forwarding
 * so that anyone can use it.
 * @param packetData
 * @param sw
 * @param ports
 * @param cntx
 */
@LogMessageDoc(level="ERROR",
        message="Failed to clear all flows on switch {switch}",
        explanation="An I/O error occured while trying send " +
        		"topology discovery packet",
        recommendation=LogMessageDoc.CHECK_SWITCH)
public void doMultiActionPacketOut(byte[] packetData, IOFSwitch sw,
                                   Set<Short> ports,
                                   ListenerContext cntx) {

    if (ports == null) return;
    if (packetData == null || packetData.length <= 0) return;

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

    List<OFAction> actions = new ArrayList<OFAction>();
    for(short p: ports) {
        actions.add(new OFActionOutput(p, (short) 0));
    }

    // set actions
    po.setActions(actions);
    // set action length
    po.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH *
            ports.size()));
    // set buffer-id to BUFFER_ID_NONE
    po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    // set in-port to OFPP_NONE
    po.setInPort(OFPort.OFPP_NONE.getValue());

    // set packet data
    po.setPacketData(packetData);

    // compute and set packet length.
    short poLength = (short)(OFPacketOut.MINIMUM_LENGTH +
            po.getActionsLength() +
            packetData.length);

    po.setLength(poLength);

    try {
        //counterStore.updatePktOutFMCounterStore(sw, po);
        if (log.isTraceEnabled()) {
            log.trace("write broadcast packet on switch-id={} " +
                    "interaces={} packet-data={} packet-out={}",
                    new Object[] {sw.getId(), ports, packetData, po});
        }
        sw.write(po, cntx);

    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:63,代码来源:TopologyManager.java

示例14: verifyTunnelLiveness

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
private void verifyTunnelLiveness(long srcDPID, long dstDPID) {

        if (tunnelManager == null) {
            log.warn("Cannot veirfy tunnel without tunnel manager.");
            return;
        }

        // If the tunnel end-points are not active, there's no point in
        // verifying liveness.
        if (!tunnelManager.isTunnelActiveByDpid(srcDPID)) {
            if (log.isTraceEnabled()) {
                log.trace("Switch {} is not in tunnel active state," +
                        " cannot verify tunnel liveness.", srcDPID);
            }
            return;
        }
        if (!tunnelManager.isTunnelActiveByDpid(dstDPID)) {
            if (log.isTraceEnabled()) {
                log.trace("Switch {} is not in tunnel active state," +
                        " cannot verify tunnel liveness.", dstDPID);
            }
            return;
        }

        // At this point, both endpoints are tunnel active.
        Short srcPort = tunnelManager.getTunnelPortNumber(srcDPID);
        Integer dstIpAddr = tunnelManager.getTunnelIPAddr(dstDPID);

        IOFSwitch iofSwitch = controllerProvider.getSwitches().get(srcDPID);
        if (iofSwitch == null) {
            if (log.isTraceEnabled()) {
                log.trace("Cannot send tunnel LLDP as switch object does " +
                        "not exist for DPID {}", srcDPID);
            }
            return;
        }

        // Generate and send an LLDP to the tunnel port of srcDPID
        OFPacketOut po = linkDiscovery.generateLLDPMessage(srcDPID,
                                                           srcPort.shortValue(),
                                                           true, false);

        List<OFAction> actions = new ArrayList<OFAction>();
        short actionsLength = 0;

        // Set the tunnel destination action
        OFActionTunnelDstIP tunnelDstAction =
                new OFActionTunnelDstIP(dstIpAddr.intValue());
        actions.add(tunnelDstAction);
        actionsLength += tunnelDstAction.getLengthU();

        // Set the output port action
        OFActionOutput outputAction = new OFActionOutput();
        outputAction.setPort(srcPort.shortValue());
        actions.add(outputAction);
        actionsLength += outputAction.getLengthU();

        po.setActions(actions);
        po.setActionsLength(actionsLength);
        po.setLengthU(po.getLengthU() + actionsLength);

        try {
            iofSwitch.write(po, null);
            iofSwitch.flush();
            // once the LLDP is written, add the tunnel event to the
            // checkTunnelLivenessQueue
            OrderedNodePair onp = new OrderedNodePair(srcDPID, dstDPID);
            this.tunnelVerificationQueue.add(onp);
        } catch (IOException e) {
            log.error("Failure sending LLDP out port {} on switch {}",
                      new Object[] { srcPort, iofSwitch.getStringId() }, e);
        }
    }
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:74,代码来源:BetterTopologyManager.java

示例15: doFlood

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
/**
 * Creates a OFPacketOut with the OFPacketIn data that is flooded on all ports unless 
 * the port is blocked, in which case the packet will be dropped.
 * @param sw The switch that receives the OFPacketIn
 * @param pi The OFPacketIn that came to the switch
 * @param cntx The FloodlightContext associated with this OFPacketIn
 */
@LogMessageDoc(level="ERROR",
               message="Failure writing PacketOut " +
               		"switch={switch} packet-in={packet-in} " +
               		"packet-out={packet-out}",
               explanation="An I/O error occured while writing a packet " +
               		"out message to the switch",
               recommendation=LogMessageDoc.CHECK_SWITCH)
protected void doFlood(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
    if (topology.isIncomingBroadcastAllowed(sw.getId(),
                                            pi.getInPort()) == false) {
        if (log.isTraceEnabled()) {
            log.trace("doFlood, drop broadcast packet, pi={}, " + 
                      "from a blocked port, srcSwitch=[{},{}], linkInfo={}",
                      new Object[] {pi, sw.getId(),pi.getInPort()});
        }
        return;
    }

    // Set Action to flood
    OFPacketOut po = 
        (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
    List<OFAction> actions = new ArrayList<OFAction>();
    if (sw.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_FLOOD)) {
        actions.add(new OFActionOutput(OFPort.OFPP_FLOOD.getValue(), 
                                       (short)0xFFFF));
    } else {
        actions.add(new OFActionOutput(OFPort.OFPP_ALL.getValue(), 
                                       (short)0xFFFF));
    }
    po.setActions(actions);
    po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);

    // set buffer-id, in-port and packet-data based on packet-in
    short poLength = (short)(po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH);
    po.setBufferId(pi.getBufferId());
    po.setInPort(pi.getInPort());
    if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
        byte[] packetData = pi.getPacketData();
        poLength += packetData.length;
        po.setPacketData(packetData);
    }
    po.setLength(poLength);
    
    try {
        if (log.isTraceEnabled()) {
            log.trace("Writing flood PacketOut switch={} packet-in={} packet-out={}",
                      new Object[] {sw, pi, po});
        }
        messageDamper.write(sw, po, cntx);
    } catch (IOException e) {
        log.error("Failure writing PacketOut switch={} packet-in={} packet-out={}",
                new Object[] {sw, pi, po}, e);
    }            

    return;
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:64,代码来源:Forwarding.java


注:本文中的org.openflow.protocol.OFPacketOut.setActionsLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。