def genPacketOut(parent,
                 xid=None,
                 buffer_id=None,
                 in_port=ofp.OFPP_NONE,
                 action_ports=[],
                 pkt=simplePacket()):
    """
    Create a packet_out message with genericly usable values
    @param parent parent must have logger (Logging object)
    @param xid transaction ID used in OpenFlow header
    @param buffer_id bufer_id
    @param in_port ingress port
    @param action_ports a list of output ports
    @param pkt a packet to be attached on packet_out
    @return packet_out
    """
    if xid == None:
        xid = genVal32bit()
    if buffer_id == None:
        buffer_id = 0xffffffff

    packet_out = message.packet_out()
    packet_out.header.xid = xid
    packet_out.buffer_id = buffer_id
    packet_out.in_port = in_port

    for action_port in action_ports:
        act = action.action_output()
        act.port = action_port
        act.max_len = 0x80
        parent.assertTrue(packet_out.actions.add(act), 'Could not add action to msg')
    if pkt is not None:
        packet_out.data = str(pkt)
    return packet_out
Beispiel #2
0
def genPacketOut(parent,
                 xid=None,
                 buffer_id=None,
                 in_port=ofp.OFPP_NONE,
                 action_ports=[],
                 pkt=simplePacket()):
    """
    Create a packet_out message with genericly usable values
    @param parent parent must have logger (Logging object)
    @param xid transaction ID used in OpenFlow header
    @param buffer_id bufer_id
    @param in_port ingress port
    @param action_ports a list of output ports
    @param pkt a packet to be attached on packet_out
    @return packet_out
    """
    if xid == None:
        xid = genVal32bit()
    if buffer_id == None:
        buffer_id = 0xffffffff

    packet_out = message.packet_out()
    packet_out.header.xid = xid
    packet_out.buffer_id = buffer_id
    packet_out.in_port = in_port

    for action_port in action_ports:
        act = action.action_output()
        act.port = action_port
        act.max_len = 0x80
        parent.assertTrue(packet_out.actions.add(act),
                          'Could not add action to msg')
    if pkt is not None:
        packet_out.data = str(pkt)
    return packet_out
Beispiel #3
0
def genFloModFromPkt(parent,
                     pkt,
                     ing_port=ofp.OFPP_NONE,
                     action_list=None,
                     wildcards=0,
                     egr_port=None):
    """
    Create a flow_mod message from a packet
    The created flow_mod will match on the given packet with given wildcards.
    @param parent parent must have logger (Logging object)
    @param pkt Parsed and used to construct a flow_mod
    @param ing_port ingress port
    @param action_list list of actions
    @param wildcards Used as a field on match structure
    @param egr_port Used for output action
    @return flow_mod
    """
    logprefix = "FlowMsgCreate: "
    match = parse.packet_to_flow_match(pkt)
    parent.assertTrue(match is not None, "Flow match from pkt failed")
    match.wildcards = wildcards
    match.in_port = ing_port

    request = message.flow_mod()
    request.match = match
    request.buffer_id = 0xffffffff

    if action_list is not None:
        for act in action_list:
            parent.logger.debug(logprefix + "Adding action " + act.show())
            rv = request.actions.add(act)
            parent.assertTrue(rv, "Could not add action" + act.show())

    # Set up output/enqueue action if directed
    if egr_port is not None:
        act = action.action_output()
        act.port = egr_port
        rv = request.actions.add(act)
        parent.assertTrue(rv, "Could not add output action " + str(egr_port))

    parent.logger.debug(logprefix + str(request.show()))

    return request
def genFloModFromPkt(parent, pkt, ing_port=ofp.OFPP_NONE, action_list=None, wildcards=0,
                     egr_port=None):
    """
    Create a flow_mod message from a packet
    The created flow_mod will match on the given packet with given wildcards.
    @param parent parent must have logger (Logging object)
    @param pkt Parsed and used to construct a flow_mod
    @param ing_port ingress port
    @param action_list list of actions
    @param wildcards Used as a field on match structure
    @param egr_port Used for output action
    @return flow_mod
    """
    logprefix = "FlowMsgCreate: "
    match = parse.packet_to_flow_match(pkt)
    parent.assertTrue(match is not None, "Flow match from pkt failed")
    match.wildcards = wildcards
    match.in_port = ing_port

    request = message.flow_mod()
    request.match = match
    request.buffer_id = 0xffffffff

    if action_list is not None:
        for act in action_list:
            parent.logger.debug(logprefix + "Adding action " + act.show())
            rv = request.actions.add(act)
            parent.assertTrue(rv, "Could not add action" + act.show())

    # Set up output/enqueue action if directed
    if egr_port is not None:
        act = action.action_output()
        act.port = egr_port
        rv = request.actions.add(act)
        parent.assertTrue(rv, "Could not add output action " + str(egr_port))

    parent.logger.debug(logprefix + str(request.show()))

    return request