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


Java OFPacketOut.BUFFER_ID_NONE属性代码示例

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


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

示例1: receive

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,代码行数:31,代码来源:Hub.java

示例2: pushPacket

/**
 * Pushes a packet-out to a switch.  The assumption here is that
 * the packet-in was also generated from the same switch.  Thus, if the input
 * port of the packet-in and the outport are the same, the function will not
 * push the packet-out.
 * @param sw        switch that generated the packet-in, and from which packet-out is sent
 * @param match     OFmatch
 * @param pi        packet-in
 * @param outport   output port
 */
private void pushPacket(IOFSwitch sw, OFMatch match, OFPacketIn pi, short outport) {
    if (pi == null) {
        return;
    }

    // The assumption here is (sw) is the switch that generated the
    // packet-in. If the input port is the same as output port, then
    // the packet-out should be ignored.
    if (pi.getInPort() == outport) {
        if (log.isDebugEnabled()) {
            log.debug("Attempting to do packet-out to the same " +
                      "interface as packet-in. Dropping packet. " +
                      " SrcSwitch={}, match = {}, pi={}",
                      new Object[]{sw, match, pi});
            return;
        }
    }

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

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

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

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

    // If the switch doens't support buffering set the buffer id to be none
    // otherwise it'll be the the buffer id of the PacketIn
    if (sw.getBuffers() == 0) {
        // We set the PI buffer id here so we don't have to check again below
        pi.setBufferId(OFPacketOut.BUFFER_ID_NONE);
        po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    } else {
        po.setBufferId(pi.getBufferId());
    }

    po.setInPort(pi.getInPort());

    // If the buffer id is none or the switch doesn's support buffering
    // we send the data with the packet out
    if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
        byte[] packetData = pi.getPacketData();
        poLength += packetData.length;
        po.setPacketData(packetData);
    }

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, po);
        sw.write(po, null);
    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:75,代码来源:LearningSwitch.java

示例3: writePacketOutForPacketIn

/**
 * 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,代码行数:50,代码来源:LearningSwitch.java

示例4: pushPacket

/**
 * used to push any packet - borrowed routine from Forwarding
 * 
 * @param OFPacketIn pi
 * @param IOFSwitch sw
 * @param int bufferId
 * @param short inPort
 * @param short outPort
 * @param FloodlightContext cntx
 * @param boolean flush
 */    
public void pushPacket(IPacket packet, 
                       IOFSwitch sw,
                       int bufferId,
                       short inPort,
                       short outPort, 
                       FloodlightContext cntx,
                       boolean flush) {
    if (log.isTraceEnabled()) {
        log.trace("PacketOut srcSwitch={} inPort={} outPort={}", 
                  new Object[] {sw, inPort, outPort});
    }

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

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

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

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

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

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, po);
        messageDamper.write(sw, po, cntx, flush);
    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:63,代码来源:LoadBalancer.java

示例5: pushPacket

/**
 * Pushes a packet-out to a switch. If bufferId != BUFFER_ID_NONE we 
 * assume that the packetOut switch is the same as the packetIn switch
 * and we will use the bufferId 
 * Caller needs to make sure that inPort and outPort differs
 * @param packet    packet data to send
 * @param sw        switch from which packet-out is sent
 * @param bufferId  bufferId
 * @param inPort    input port
 * @param outPort   output port
 * @param cntx      context of the packet
 * @param flush     force to flush the packet.
 */
@LogMessageDocs({
    @LogMessageDoc(level="ERROR",
        message="BufferId is not and packet data is null. " +
                "Cannot send packetOut. " +
                "srcSwitch={dpid} inPort={port} outPort={port}",
        explanation="The switch send a malformed packet-in." +
                    "The packet will be dropped",
        recommendation=LogMessageDoc.REPORT_SWITCH_BUG),
    @LogMessageDoc(level="ERROR",
        message="Failure writing packet out",
        explanation="An I/O error occurred while writing a " +
                "packet out to a switch",
        recommendation=LogMessageDoc.CHECK_SWITCH)            
})
public void pushPacket(IPacket packet, 
                       IOFSwitch sw,
                       int bufferId,
                       short inPort,
                       short outPort, 
                       FloodlightContext cntx,
                       boolean flush) {
    
    
    if (log.isTraceEnabled()) {
        log.trace("PacketOut srcSwitch={} inPort={} outPort={}", 
                  new Object[] {sw, inPort, outPort});
    }

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

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

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

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

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

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStore(sw, po);
        messageDamper.write(sw, po, cntx, flush);
    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:81,代码来源:ForwardingBase.java

示例6: writePacketOutForPacketIn

/**
 * 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,代码行数:50,代码来源:LearningSwitch.java

示例7: pushPacket

private void pushPacket(IOFSwitch sw, OFMatch match, OFPacketIn pi, short outport, List<OFAction> actions, int actionLen)
{
    if (pi == null) {
        return;
    }

    // The assumption here is (sw) is the switch that generated the
    // packet-in. If the input port is the same as output port, then
    // the packet-out should be ignored.
    if (pi.getInPort() == outport) {
        if (logger.isDebugEnabled()) {
            logger.debug("Attempting to do packet-out to the same " +
                      "interface as packet-in. Dropping packet. " +
                      " SrcSwitch={}, match = {}, pi={}",
                      new Object[]{sw, match, pi});
            return;
        }
    }

    if (logger.isTraceEnabled()) {
        logger.trace("PacketOut srcSwitch={} match={} pi={}",
                  new Object[] {sw, match, pi});
    }

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

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

    // If the switch doens't support buffering set the buffer id to be none
    // otherwise it'll be the the buffer id of the PacketIn
    if (sw.getBuffers() == 0) {
        // We set the PI buffer id here so we don't have to check again below
        pi.setBufferId(OFPacketOut.BUFFER_ID_NONE);
        po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    } else {
        po.setBufferId(pi.getBufferId());
    }

    po.setInPort(pi.getInPort());

    // If the buffer id is none or the switch doesn's support buffering
    // we send the data with the packet out
    if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
        byte[] packetData = pi.getPacketData();
        poLength += packetData.length;
        po.setPacketData(packetData);
    }

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, po);
        sw.write(po, null);
        sw.flush();
    } catch (IOException e) {
        logger.error("Failure writing packet out", e);
    }
}
 
开发者ID:shao-you,项目名称:SDN-Traceroute,代码行数:63,代码来源:Traceroute.java

示例8: add

/**
 * Adds flow for given switch, outgoing port, and incoming packet.
 * Constructs {@link OFMatch} from the incoming packet and instructs switch
 * to send all packets from the flow to be sent to given outgoing port. The
 * received packet is sent do switch for forwarding.
 *
 * @param sw swithc
 * @param floodlightProvider Floodlight controller
 * @param cntx Floodlight context
 * @param outPort outgoing port
 * @param pi incoming packet
 */
public static void add(IOFSwitch sw, IFloodlightProviderService floodlightProvider, FloodlightContext cntx, short outPort, OFPacketIn pi) {
    logger.debug("add(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) begin");

    OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);

    // Parse the received packet
    OFMatch match = new OFMatch();
    match.loadFromPacket(pi.getPacketData(), pi.getInPort());

    match.setWildcards(0);
    flowMod.setMatch(match);

    flowMod.setCommand(OFFlowMod.OFPFC_ADD);
    flowMod.setIdleTimeout((short) 11);
    flowMod.setHardTimeout((short) 0);
    flowMod.setPriority((short) 50);
    flowMod.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    flowMod.setFlags((short) 1);

    List<OFAction> actions = new ArrayList<>();
    actions.add(new OFActionOutput().setPort(outPort));
    flowMod.setActions(actions);
    flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH);

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

    po.setActions(actions);
    po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);

    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);

    List<OFMessage> msglist = new ArrayList<>();
    msglist.add(flowMod);
    msglist.add(po);
    try {
        sw.write(msglist, cntx);
        sw.flush();
        logger.debug(String.format("Flow rule (out port %d) added to switch %s", outPort, sw.getStringId()));
    } catch (IOException ex) {
        logger.error(String.format("Error while adding flow rule (out port %d) to switch %s", outPort, sw.getStringId()), ex);
    }
    logger.debug("add(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) end");
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:64,代码来源:Flows.java

示例9: doFlood

/**
 * 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,代码行数:63,代码来源:Forwarding.java

示例10: pushPacket

private void pushPacket(IOFSwitch sw, OFPacketIn pi,
		ArrayList<Link> outLinks, FloodlightContext cntx) {
	// TODO Auto-generated method stub
	if (pi == null) {
           return;
       }
	
	if (log.isTraceEnabled()) {
           log.trace("PacketOut srcSwitch={} pi={}",
                     new Object[] {sw, pi});
       }

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

       // set actions
       List<OFAction> actions = new ArrayList<OFAction>();
       for(Link link: outLinks){
       	Short outport = link.getOtherPort(sw.getId());
       	OFActionOutput action = new OFActionOutput(outport, (short) 0xffff);
           actions.add(action);
       }
       po.setActions(actions)
       	.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH *
               outLinks.size()));
       
       short poLength =
               (short) (po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH);
       int bufferID = pi.getBufferId();
       if( bufferID!=0 && bufferID != OFPacketOut.BUFFER_ID_NONE)
           po.setBufferId(pi.getBufferId());
       else {
           po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
       }
       if (po.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
           byte[] packetData = pi.getPacketData();
           poLength += packetData.length;
           po.setPacketData(packetData);
       }
       po.setInPort(pi.getInPort());
       po.setLength(poLength);
       try {
           counterStore.updatePktOutFMCounterStoreLocal(sw, po);
           messageDamper.write(sw, po, cntx);
       } catch (IOException e) {
           log.error("Failure writing packet out", e);
       }

}
 
开发者ID:daniel666,项目名称:multicastSDN,代码行数:50,代码来源:IGMPCapture.java

示例11: pushPacket

public void pushPacket(IPacket packet, 
                       IOFSwitch sw,
                       int bufferId,
                       short inPort,
                       short outPort,
                       Long nextHopSwitchDPID,
                       ListenerContext cntx,
                       boolean flush) {

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

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

    // set actions
    int actionsLength = 0;
    List<OFAction> actions = new ArrayList<OFAction>();

    Short tunnelPort = tunnelManager.getTunnelPortNumber(sw.getId());
    if (tunnelPort != null && tunnelPort.shortValue() == outPort) {
        if (nextHopSwitchDPID == null) {
            log.error("No IP address assigned for tunnel port. sw = {}",
                    nextHopSwitchDPID);
            return;
        }
        Integer ipAddr = 
                tunnelManager.getTunnelIPAddr(nextHopSwitchDPID.longValue());

        if (ipAddr == null) {
            log.error("IP Address of tunnel port is not defined. {}",
                      nextHopSwitchDPID);
            return;
        }
        OFActionTunnelDstIP tunnelDstAction =
                new OFActionTunnelDstIP(ipAddr.intValue());
        actions.add(tunnelDstAction);
        actionsLength += tunnelDstAction.getLengthU();
    }

    // Output action should be set after the tunnel destination, if present
    actions.add(new OFActionOutput(outPort, (short) 0xffff));

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

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

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

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, po);
        messageDamper.write(sw, po, cntx, flush);
    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:79,代码来源:Forwarding.java

示例12: pushPacket

/**
 * Pushes a packet-out to a switch.  The assumption here is that
 * the packet-in was also generated from the same switch.  Thus, if the input
 * port of the packet-in and the outport are the same, the function will not 
 * push the packet-out.
 * @param sw        switch that generated the packet-in, and from which packet-out is sent
 * @param match     OFmatch
 * @param pi        packet-in
 * @param outport   output port
 */
private void pushPacket(IOFSwitch sw, OFMatch match, OFPacketIn pi, short outport) {
    if (pi == null) {
        return;
    }

    // The assumption here is (sw) is the switch that generated the 
    // packet-in. If the input port is the same as output port, then
    // the packet-out should be ignored.
    if (pi.getInPort() == outport) {
        if (log.isDebugEnabled()) {
            log.debug("Attempting to do packet-out to the same " + 
                      "interface as packet-in. Dropping packet. " + 
                      " SrcSwitch={}, match = {}, pi={}", 
                      new Object[]{sw, match, pi});
            return;
        }
    }

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

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

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

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

    // If the switch doens't support buffering set the buffer id to be none
    // otherwise it'll be the the buffer id of the PacketIn
    if (sw.getBuffers() == 0) {
        // We set the PI buffer id here so we don't have to check again below
        pi.setBufferId(OFPacketOut.BUFFER_ID_NONE);
        po.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    } else {
        po.setBufferId(pi.getBufferId());
    }

    po.setInPort(pi.getInPort());

    // If the buffer id is none or the switch doesn's support buffering
    // we send the data with the packet out
    if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
        byte[] packetData = pi.getPacketData();
        poLength += packetData.length;
        po.setPacketData(packetData);
    }

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, po);
        sw.write(po, null);
    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:75,代码来源:LearningSwitch.java

示例13: writePacketOutForPacketIn

/**
 * 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) controllerProvider.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:opendaylight,项目名称:archived-net-virt-platform,代码行数:50,代码来源:LearningSwitch.java

示例14: pushPacket

/**
 * used to push any packet - borrowed routine from Forwarding
 * 
 * @param OFPacketIn pi
 * @param IOFSwitch sw
 * @param int bufferId
 * @param short inPort
 * @param short outPort
 * @param ListenerContext cntx
 * @param boolean flush
 */    
public void pushPacket(IPacket packet, 
                       IOFSwitch sw,
                       int bufferId,
                       short inPort,
                       short outPort, 
                       ListenerContext cntx,
                       boolean flush) {
    if (log.isTraceEnabled()) {
        log.trace("PacketOut srcSwitch={} inPort={} outPort={}", 
                  new Object[] {sw, inPort, outPort});
    }

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

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

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

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

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

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStoreLocal(sw, po);
        messageDamper.write(sw, po, cntx, flush);
    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:63,代码来源:LoadBalancer.java

示例15: pushPacket

/**
 * Pushes a packet-out to a switch. If bufferId != BUFFER_ID_NONE we 
 * assume that the packetOut switch is the same as the packetIn switch
 * and we will use the bufferId 
 * Caller needs to make sure that inPort and outPort differs
 * @param packet    packet data to send
 * @param sw        switch from which packet-out is sent
 * @param bufferId  bufferId
 * @param inPort    input port
 * @param outPort   output port
 * @param cntx      context of the packet
 * @param flush     force to flush the packet.
 */
@LogMessageDocs({
    @LogMessageDoc(level="ERROR",
        message="BufferId is not and packet data is null. " +
                "Cannot send packetOut. " +
                "srcSwitch={dpid} inPort={port} outPort={port}",
        explanation="The switch send a malformed packet-in." +
                    "The packet will be dropped",
        recommendation=LogMessageDoc.REPORT_SWITCH_BUG),
    @LogMessageDoc(level="ERROR",
        message="Failure writing packet out",
        explanation="An I/O error occurred while writing a " +
                "packet out to a switch",
        recommendation=LogMessageDoc.CHECK_SWITCH),            
})
public void pushPacket(IPacket packet, 
                       IOFSwitch sw,
                       int bufferId,
                       short inPort,
                       short outPort, 
                       FloodlightContext cntx,
                       boolean flush) {
    
    
    if (log.isTraceEnabled()) {
        log.trace("PacketOut srcSwitch={} inPort={} outPort={}", 
                  new Object[] {sw, inPort, outPort});
    }

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

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

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

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

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

    po.setLength(poLength);

    try {
        counterStore.updatePktOutFMCounterStore(sw, po);
        messageDamper.write(sw, po, cntx, flush);
    } catch (IOException e) {
        log.error("Failure writing packet out", e);
    }
}
 
开发者ID:jimmyoic,项目名称:floodlight-qosmanager,代码行数:81,代码来源:ForwardingBase.java


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