Yes, just now I change the event to like that
def _handle_PacketIn (event):
        packet = event.parsed
        msg = of.ofp_flow_mod()
        msg.match = of.ofp_match.from_packet(packet, event.port);
        msg.buffer_id = event.ofp.buffer_id
        msg.idle_timeout = 10
        msg.idle_timeout = 30
        msg.actions.append(of.ofp_action_output(port = 1))
        msg.data = event.ofp
        event.connection.send(msg)


def launch ():
    '''
    Starting the Firewall module
    '''
    core.openflow.addListenerByName("PacketIn", _handle_PacketIn)
    log.info("test miss flow")


It seems it can work. However, pox still gives this warning:
INFO:packet:(udp parse) warning UDP packet data shorter than UDP len: 96 < 962
INFO:packet:(udp parse) warning UDP packet data shorter than UDP len: 96 < 962


Can you give some guidance, why it has this warning.


This is my packet_in message 
void get_header(struct request *req, struct ofp_packet_in *pi)
{
        char *header;
        struct rte_mbuf  *pkt = req->pkt;
        header = (char *)(rte_pktmbuf_mtod(pkt, unsigned char *));
        memcpy(pi->data, header, OFP_DEFAULT_MISS_SEND_LEN);
}


static int make_packet_in(int xid, int buffer_id, char *buf)
{
        struct ofp_packet_in *pi;
        struct request *req;
        int len;
        pi = (struct ofp_packet_in *)buf;
        pi->header.version = OFP_VERSION;
        pi->header.type = OFPT_PACKET_IN;
        pi->header.xid = htonl(xid);
        req = (struct request *)ring_peek(&to_channel, buffer_id);
        if (req == NULL) {
                fprintf(stderr, "req NULL pointer.\n");
                return 0;
        }
        else {
                pi->in_port = req->in_port;
                pi->buffer_id = htonl(req->buffer_id);
                pi->reason = OFPR_NO_MATCH;
                pi->pad = 0;
                get_header(req, pi);
        }


        len = sizeof(*pi) + OFP_DEFAULT_MISS_SEND_LEN;
        pi->header.length = htons(len);
        pi->total_len = htons(len);
        return len;
}


Whehter the len is not correct?








At 2014-08-20 04:10:54, "Murphy McCauley" <murphy.mccau...@gmail.com> wrote:
>It seems like you want to be listening to the PacketIn event, not the 
>ConnectionUp event.
>
>-- Murphy
>
>On Aug 19, 2014, at 12:35 PM, zhang...@126.com wrote:
>
>> Hi all,
>> 
>> I want to manually set a flow for test. The switch sends a packet_in message 
>> to pox controller. 
>> This is the code:
>> from pox.core import core
>> import pox.openflow.libopenflow_01 as of
>> from pox.lib.revent import *
>> from pox.lib.addresses import IPAddr, EthAddr
>> from collections import namedtuple
>> from pox.lib.util import str_to_bool, dpid_to_str
>> from pox.lib.packet.ipv4 import ipv4
>> from pox.lib.packet.ethernet import ethernet
>> from pox.lib.packet.tcp import *
>> from pox.lib.packet.udp import *
>> import os
>> 
>> log = core.getLogger()
>> 
>> class Test_output_port (EventMixin):
>>    def __init__ (self):
>>        self.listenTo(core.openflow)
>> 
>>    def _handle_ConnectionUp (self, event):
>>        packet = event.parsed
>>        msg = of.ofp_flow_mod()
>>        msg.match = of.ofp_match.from_packet(packet, event.port);
>>        msg.buffer_id = event.ofp.buffer_id
>>        msg.idle_timeout = 10
>>        msg.idle_timeout = 30
>>        msg.actions.append(of.ofp_action_output(port = 1))
>>        msg.data = event.ofp
>>        event.connection.send(msg), 
>> 
>> def launch ():
>>    '''
>>    Starting the Firewall module
>>    '''
>>    core.registerNew(Test_output_port)
>> 
>> When test, it shows the following error. If anybody knows the reason, and 
>> can give some help, I will appreciate. 
>> POX 0.2.0 (carp) / Copyright 2011-2013 James McCauley, et al.
>> DEBUG:core:POX 0.2.0 (carp) going up...
>> DEBUG:core:Running on CPython (2.7.3/Sep 26 2013 20:03:06)
>> DEBUG:core:Platform is 
>> Linux-3.2.0-58-generic-x86_64-with-Ubuntu-12.04-precise
>> INFO:core:POX 0.2.0 (carp) is up.
>> DEBUG:openflow.of_01:Listening on 0.0.0.0:6633
>> WARNING:openflow.of_01:<class 'pox.openflow.PacketIn'> raised on dummy 
>> OpenFlow nexus
>> INFO:openflow.of_01:[00-00-00-00-00-01 1] connected
>> ERROR:core:Exception while handling OpenFlowNexus!ConnectionUp...
>> Traceback (most recent call last):
>>  File "/home/guest/controller/pox/pox/lib/revent/revent.py", line 231, in 
>> raiseEventNoErrors
>>    return self.raiseEvent(event, *args, **kw)
>>  File "/home/guest/controller/pox/pox/lib/revent/revent.py", line 278, in 
>> raiseEvent
>>    rv = event._invoke(handler, *args, **kw)
>>  File "/home/guest/controller/pox/pox/lib/revent/revent.py", line 156, in 
>> _invoke
>>    return handler(self, *args, **kw)
>>  File "/home/guest/controller/pox/pox/misc/test_flow_miss.py", line 25, in 
>> _handle_ConnectionUp
>>    packet = event.parsed
>> AttributeError: 'ConnectionUp' object has no attribute 'parsed'

Reply via email to