Revision: 483
          http://vde.svn.sourceforge.net/vde/?rev=483&view=rev
Author:   rd235
Date:     2011-03-28 10:05:45 +0000 (Mon, 28 Mar 2011)

Log Message:
-----------
step three: new queueing discipline. Packets get sent as soon as possible, 
pollout on connected sockets wakes up the queue

Modified Paths:
--------------
    branches/rd235/vde-2/include/vde.h
    branches/rd235/vde-2/src/vde_switch/consmgmt.c
    branches/rd235/vde-2/src/vde_switch/datasock.c
    branches/rd235/vde-2/src/vde_switch/packetq.c
    branches/rd235/vde-2/src/vde_switch/packetq.h
    branches/rd235/vde-2/src/vde_switch/port.c
    branches/rd235/vde-2/src/vde_switch/port.h
    branches/rd235/vde-2/src/vde_switch/tuntap.c
    branches/rd235/vde-2/src/vde_switch/vde_switch.c

Modified: branches/rd235/vde-2/include/vde.h
===================================================================
--- branches/rd235/vde-2/include/vde.h  2011-03-27 21:04:28 UTC (rev 482)
+++ branches/rd235/vde-2/include/vde.h  2011-03-28 10:05:45 UTC (rev 483)
@@ -18,12 +18,6 @@
 #define DO_SYSLOG
 #define VDE_IP_LOG
 
-/*
- * Enable the new packet queueing. Experimental but recommended
- * (expecially with Darwin and other BSDs)
- */
-#define VDE_PQ
-#define VDE_PQ_PPOLL
-#define VDE_PQ_DYNAMIC
+#define VDE_PQ2
 
 #endif

Modified: branches/rd235/vde-2/src/vde_switch/consmgmt.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/consmgmt.c      2011-03-27 21:04:28 UTC 
(rev 482)
+++ branches/rd235/vde-2/src/vde_switch/consmgmt.c      2011-03-28 10:05:45 UTC 
(rev 483)
@@ -648,7 +648,6 @@
                        qtime());
        if (mgmt_socket)
                printoutc(fd,"mgmt %s perm 0%03o",mgmt_socket,mgmt_mode);
-       printoutc(fd,"unsent_pktq_len %d",packetq_count());
        return 0;
 }
 

Modified: branches/rd235/vde-2/src/vde_switch/datasock.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/datasock.c      2011-03-27 21:04:28 UTC 
(rev 482)
+++ branches/rd235/vde-2/src/vde_switch/datasock.c      2011-03-28 10:05:45 UTC 
(rev 483)
@@ -85,18 +85,13 @@
 
 static int send_datasock(int fd_ctl, int fd_data, void *packet, int len, int 
port)
 {
-       int n;
-
-       n = len - send(fd_data, packet, len, 0);
-       if(n){
+       if (send(fd_data, packet, len, 0) < 0) {
                int rv=errno;
-#ifndef VDE_PQ
-               if(errno != EAGAIN && errno != EWOULDBLOCK) 
printlog(LOG_WARNING,"send_sockaddr port %d: %s",port,strerror(errno));
-#endif
-               if (n>len)
-                       return -rv;
+               if(rv != EAGAIN && rv != EWOULDBLOCK) 
+                       printlog(LOG_WARNING,"send_sockaddr port %d: 
%s",port,strerror(errno));
                else
-                       return n;
+                       rv=EWOULDBLOCK;
+               return -rv;
        }
        return 0;
 }
@@ -209,18 +204,24 @@
 {
        struct endpoint *ep=arg;
        if (type == data_type) {
-               struct bipacket packet;
-               int len;
+#ifdef VDE_PQ2
+               if (revents & POLLOUT)
+                       handle_out_packet(ep);
+#endif
+               if (revents & POLLIN) {
+                       struct bipacket packet;
+                       int len;
 
-               len=recv(fd, &(packet.p), sizeof(struct packet),0);
-               if(len < 0){
-                       if (errno == EAGAIN || errno == EWOULDBLOCK) return;
-                       printlog(LOG_WARNING,"Reading  data: 
%s",strerror(errno));
+                       len=recv(fd, &(packet.p), sizeof(struct packet),0);
+                       if(len < 0){
+                               if (errno == EAGAIN || errno == EWOULDBLOCK) 
return;
+                               printlog(LOG_WARNING,"Reading  data: 
%s",strerror(errno));
+                       }
+                       else if(len == 0) 
+                               printlog(LOG_WARNING,"EOF data port: 
%s",strerror(errno));
+                       else if(len >= ETH_HEADER_SIZE)
+                               handle_in_packet(ep, &(packet.p), len);
                }
-               else if(len == 0) 
-                       printlog(LOG_WARNING,"EOF data port: 
%s",strerror(errno));
-               else if(len >= ETH_HEADER_SIZE)
-                       handle_in_packet(ep, &(packet.p), len);
        }
        else if (type == wd_type) {
                char reqbuf[REQBUFLEN+1];

Modified: branches/rd235/vde-2/src/vde_switch/packetq.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/packetq.c       2011-03-27 21:04:28 UTC 
(rev 482)
+++ branches/rd235/vde-2/src/vde_switch/packetq.c       2011-03-28 10:05:45 UTC 
(rev 483)
@@ -1,8 +1,7 @@
 /*
  * packetq - packet queue management. try to send packets several times before 
discarding.
- * Copyright 2005,...,2011 Renzo Davoli
+ * Copyright 2011 Renzo Davoli
  * Licensed under the GPLv2
- * 2011 Thanks to Simone Abbakus for the idea of dynamic delay
  */
 
 #include <stdlib.h>
@@ -21,196 +20,84 @@
 
 #include "consmgmt.h"
 
-#define TIMES 10
-#define MAXQLEN 4192
+#ifdef VDE_PQ2
 
-#ifdef VDE_PQ
-#include "packetq.h"
-#include <time.h>
+struct packetbuf {
+       short len;
+       short count;
+};
 
-#ifdef VDE_PQ_PPOLL
-
-#ifdef CLOCK_MONOTONIC_RAW
-#define CLOCK_TYPE CLOCK_MONOTONIC_RAW
-#else
-#define CLOCK_TYPE CLOCK_MONOTONIC
-#endif
-struct timespec *packetq_timeout;
-static struct timespec packetq_timeout_value;
-#ifdef VDE_PQ_DYNAMIC
-#define TIMEOUT_MAX 10000000 //Upper bound 10ms
-#define TIMEOUT_MIN  1000000 //Lower bound  1ms
-#define TIMEOUT_MEAN ((TIMEOUT_MAX + TIMEOUT_MIN) / 2)
-#define TIMEOUT_STEP ((TIMEOUT_MAX - TIMEOUT_MIN) / MAXQLEN)
-#else
-#define TIMEOUT_NS 5000000
-#endif
-#else
-
-int packetq_timeout= -1;
-#define TIMEOUT 5
-#endif
-
-static int countq;
-
-struct packetqq {
-       int (*sender)(int fd_ctl, int fd_data, void *packet, int len, int port);
-       int fd_ctl; 
-       int fd_data; 
-       void *packet; 
-       int len; 
-       int port;
-       int times;
-       struct packetqq *next;
+struct vdepq {
+       struct packetbuf *vdepq_pb;
+       struct vdepq *vdepq_next;
 };
 
-static struct packetqq *pqh=NULL;
-static struct packetqq *pqt=NULL;
-#ifdef VDE_PQ_PPOLL
-static struct timespec last_try;
-#else
-static struct timeval last_try;
-#endif
-
-void packetq_add(int (*sender)(int fd_ctl, int fd_data, void *packet, int len, 
int port),
-               int fd_ctl, int fd_data, void *packet, int len, int port)
+int vdepq_add(struct vdepq **tail, void *packet, int len, void **tmp)
 {
-       if (countq < MAXQLEN) {
-               struct packetqq *new=malloc(sizeof(struct packetqq));
-               void *packetcopy=malloc(len);
-               if (new != NULL && packetcopy != NULL && len > 0) {
-                       countq++;
-                       new->sender=sender;
-                       new->fd_ctl=fd_ctl;
-                       new->fd_data=fd_data;
-                       memcpy(packetcopy,packet,len);
-                       new->packet=packetcopy;
-                       new->len=len;
-                       new->port=port;
-                       new->times=TIMES;
-                       new->next=NULL;
-                       if (pqh==NULL) {
-#ifdef VDE_PQ_PPOLL
-                               clock_gettime(CLOCK_TYPE,&last_try);
-#ifdef VDE_PQ_DYNAMIC
-                               packetq_timeout_value.tv_nsec=TIMEOUT_MEAN;
-#else
-                               packetq_timeout_value.tv_nsec=TIMEOUT_NS;
-#endif
-                               packetq_timeout=&packetq_timeout_value;
-#else
-                               gettimeofday(&last_try,NULL);
-                               packetq_timeout=TIMEOUT;
-#endif
-                               pqh=pqt=new;
-                       } else {
-                               pqt->next=new;
-                               pqt=new;
-                       }
-               } else {
-                       if (new != NULL) free(new);
-                       if (packetcopy != NULL) free(packetcopy);
+       struct packetbuf *packetbuftmp = *tmp;
+       struct vdepq *newelem;
+       if ((newelem = malloc(sizeof(struct vdepq))) == NULL)
+               return 0;
+       if (packetbuftmp == NULL) {
+               if ((*tmp = packetbuftmp = malloc (sizeof(struct 
packetbuf)+len))==NULL) {
+                       free(newelem);
+                       return 0;
                }
+               packetbuftmp->len=len;
+               packetbuftmp->count=0;
+               memcpy(((void *)(packetbuftmp+1)),packet,len);
        }
+       newelem->vdepq_pb=packetbuftmp;
+       (packetbuftmp->count)++;
+       //printf("add %p count %d len %d/%d 
\n",newelem,packetbuftmp->count,len,packetbuftmp->len);
+       if (*tail == NULL) 
+               *tail=newelem->vdepq_next=newelem;
+       else {
+               newelem->vdepq_next=(*tail)->vdepq_next;
+               (*tail)->vdepq_next=newelem;
+               *tail=newelem;
+       }
+       return 1;
 }
 
-static struct packetqq *packetq_scantry(struct packetqq *h,struct packetqq 
**t,fd_set *fds)
-{
-       if (h != NULL) {
-               int sendrv=!(FD_ISSET(h->fd_data,fds));
-               h->times--;
-               if ((sendrv && 
(sendrv=h->sender(h->fd_ctl,h->fd_data,h->packet,h->len,h->port)) == 0)   
/*send OK*/
-                               || h->times<=0) { /*or max number of attempts 
reached*/
-                       struct packetqq *next;
-                       next=h->next;
-                       countq--;
-                       free(h->packet);
-                       free(h);
-                       return packetq_scantry(next,t,fds);
-               } else {
-                       FD_SET(h->fd_data,fds);
-                       h->next=packetq_scantry(h->next,t,fds);
-                       if (h->next == NULL) *t=h;
-                       return h;
-               }
-       } else
-               return NULL;
-}
+#define PACKETBUFDEL(X) \
+       ({ if (--((X)->count) == 0) \
+        free(X);\
+        })
 
-void packetq_try(void)
+void vdepq_del(struct vdepq **tail)
 {
-       if (pqh != NULL) {
-#ifdef VDE_PQ_PPOLL
-               struct timespec this_try;
-               long remaining_nsecs;
-               clock_gettime(CLOCK_TYPE,&this_try);
-               /* TIMEOUT should never exceed 2.1 secs! */
-               remaining_nsecs = packetq_timeout_value.tv_nsec - 
((this_try.tv_sec-last_try.tv_sec) * 1000000000 + 
(this_try.tv_nsec-last_try.tv_nsec));
-               if (remaining_nsecs <= 0) {
-                       fd_set fds;
-                       FD_ZERO(&fds);
-                       pqh=packetq_scantry(pqh,&pqt,&fds); 
-                       if (pqh != NULL) {
-                               clock_gettime(CLOCK_TYPE,&last_try);
-#ifdef VDE_PQ_DYNAMIC
-                               packetq_timeout_value.tv_nsec = TIMEOUT_MAX - 
TIMEOUT_STEP * countq;
-#else
-                               packetq_timeout_value.tv_nsec = TIMEOUT_NS;
-#endif
-                       } else
-                               packetq_timeout = NULL;
-               } else
-                       packetq_timeout_value.tv_nsec = remaining_nsecs;
-#else
-               struct timeval this_try;
-               gettimeofday(&this_try,NULL);
-               packetq_timeout=TIMEOUT - ((this_try.tv_sec-last_try.tv_sec) * 
1000 + 
-                               (this_try.tv_usec-last_try.tv_usec) / 1000);
-               if (packetq_timeout <= 0) {
-                       fd_set fds;
-                       FD_ZERO(&fds);
-                       pqh=packetq_scantry(pqh,&pqt,&fds);     
-                       if (pqh != NULL) {
-                               gettimeofday(&last_try,NULL);
-                               packetq_timeout=TIMEOUT;
-                       } else
-                               packetq_timeout = -1;
-               }
-#endif
+       while (*tail != NULL) {
+               struct vdepq *first=(*tail)->vdepq_next;
+               //printf("kill one %p %p\n",first,*tail);
+               PACKETBUFDEL(first->vdepq_pb);
+               if (first == (*tail))
+                       *tail=NULL;
+               else
+                       (*tail)->vdepq_next=first->vdepq_next;
+               free(first);
        }
 }
 
-static struct packetqq *packetq_scandelfd(int fd_data,struct packetqq 
*h,struct packetqq **t)
-{
-       if (h != NULL) {
-               if (fd_data == h->fd_data) {
-                       struct packetqq *next=h->next;
-                       countq--;
-                       free(h->packet);
-                       free(h);
-                       return packetq_scandelfd(fd_data,next,t);
-               } else {
-                       h->next=packetq_scandelfd(fd_data,h->next,t);
-                       if (h->next == NULL) *t=h;
-                       return h;
-               }
-       } else
-               return NULL;
+int vdepq_try(struct vdepq **tail, void *ep,
+               int (*sendfun)(void *ep, void *packet, int len)) {
+       int sent=0;
+       while (*tail != NULL) {
+               struct vdepq *first = (*tail)->vdepq_next;
+               //printf("trysend %p len %d\n",first,first->vdepq_pb->len);
+               if (sendfun(ep, (void *)(first->vdepq_pb + 1), 
first->vdepq_pb->len) == -EWOULDBLOCK) 
+                       break;
+               else {
+                       PACKETBUFDEL(first->vdepq_pb);
+                       if (first == (*tail))
+                               *tail=NULL;
+                       else
+                               (*tail)->vdepq_next=first->vdepq_next;
+                       free(first);
+                       sent++;
+               } 
+       }
+       return sent;
 }
 
-void packetq_delfd(int fd_data)
-{
-       pqh=packetq_scandelfd(fd_data,pqh,&pqt);
-       if (pqh == NULL)
-#ifdef VDE_PQ_PPOLL
-               packetq_timeout = NULL;
-#else
-               packetq_timeout = -1;
 #endif
-}
-
-int packetq_count()
-{
-       return countq;
-}
-#endif

Modified: branches/rd235/vde-2/src/vde_switch/packetq.h
===================================================================
--- branches/rd235/vde-2/src/vde_switch/packetq.h       2011-03-27 21:04:28 UTC 
(rev 482)
+++ branches/rd235/vde-2/src/vde_switch/packetq.h       2011-03-28 10:05:45 UTC 
(rev 483)
@@ -4,24 +4,19 @@
  * Licensed under the GPLv2
  */
 
-#ifdef VDE_PQ
+#ifdef VDE_PQ2
 #ifndef _PACKETQ_H
 #define _PACKETQ_H
-#include <time.h>
 
-#ifdef VDE_PQ_PPOLL
-extern struct timespec *packetq_timeout;
-#else
-extern int packetq_timeout;
-#endif
+struct vdepq;
+struct endpoint;
 
-void packetq_add(int (*sender)(int fd_ctl, int fd_data, void *packet, int len, 
int port),
-               int fd, int fd_ctl, void *packet, int len, int port);
+int vdepq_add(struct vdepq **tail, void *packet, int len, void *tmp);
 
-void packetq_try(void);
+void vdepq_del(struct vdepq **tail);
 
-void packetq_delfd(int fd);
+int vdepq_try(struct vdepq **tail, struct endpoint *ep,
+               int (*sendfun)(struct endpoint *ep, void *packet, int len));
 
-int packetq_count();
 #endif
 #endif

Modified: branches/rd235/vde-2/src/vde_switch/port.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/port.c  2011-03-27 21:04:28 UTC (rev 
482)
+++ branches/rd235/vde-2/src/vde_switch/port.c  2011-03-28 10:05:45 UTC (rev 
483)
@@ -31,9 +31,7 @@
 #include "bitarray.h"
 #include "fstp.h"
 
-#ifdef VDE_PQ
 #include "packetq.h"
-#endif
 
 static int pflag=0;
 static int numports;
@@ -82,6 +80,11 @@
        int fd_ctl;
        int fd_data;
        char *descr;
+#ifdef VDE_PQ2
+       struct vdepq *vdepq;
+       int vdepq_count;
+       int vdepq_max;
+#endif
        struct endpoint *next;
 };
 
@@ -252,6 +255,11 @@
                        ep->fd_ctl=fd_ctl;
                        ep->fd_data=fd_data;
                        ep->descr=NULL;
+#ifdef VDE_PQ2
+                       ep->vdepq=NULL;
+                       ep->vdepq_count=0;
+                       ep->vdepq_max=128;
+#endif
                        if(port->ep == NULL) {/* WAS INACTIVE */
                                register int i;
                                /* copy all the vlan defs to the active vlan 
defs */
@@ -310,8 +318,8 @@
                        DBGOUT(DBGEPDEL,"Port %02d FD %2d",this->port,fd_ctl);
                        EVENTOUT(DBGEPDEL,this->port,fd_ctl);
                        *pep=this->next;
-#ifdef VDE_PQ
-                       packetq_delfd(this->fd_data);
+#ifdef VDE_PQ2
+                       vdepq_del(&(this->vdepq));
 #endif
                        if (portv[this->port]->ms->delep)
                                
portv[this->port]->ms->delep(this->fd_ctl,this->fd_data,this->descr);
@@ -380,28 +388,32 @@
 #define SEND_COUNTER_UPD(Port,LEN)
 #endif
 
-#ifdef VDE_PQ
-#define SEND_PACKET_PORT(PORT,PORTNO,PACKET,LEN) \
+#ifndef VDE_PQ2
+#define SEND_PACKET_PORT(PORT,PORTNO,PACKET,LEN,TMPBUF) \
        ({\
         struct port *Port=(PORT); \
         if (PACKETFILTER(PKTFILTOUT,(PORTNO),(PACKET), (LEN))) {\
         struct endpoint *ep; \
         SEND_COUNTER_UPD(Port,LEN); \
         for (ep=Port->ep; ep != NULL; ep=ep->next) \
-        if (Port->ms->sender(ep->fd_ctl, ep->fd_data, (PACKET), (LEN), 
ep->port)) \
-        packetq_add(Port->ms->sender,ep->fd_ctl, ep->fd_data, (PACKET), (LEN), 
ep->port); \
+        Port->ms->sender(ep->fd_ctl, ep->fd_data, (PACKET), (LEN), ep->port); \
         } \
         })
 #else
-#define SEND_PACKET_PORT(PORT,PORTNO,PACKET,LEN) \
+#define SEND_PACKET_PORT(PORT,PORTNO,PACKET,LEN,TMPBUF) \
        ({\
         struct port *Port=(PORT); \
         if (PACKETFILTER(PKTFILTOUT,(PORTNO),(PACKET), (LEN))) {\
         struct endpoint *ep; \
         SEND_COUNTER_UPD(Port,LEN); \
         for (ep=Port->ep; ep != NULL; ep=ep->next) \
-        Port->ms->sender(ep->fd_ctl, ep->fd_data, (PACKET), (LEN), ep->port); \
+        if (ep->vdepq_count || \
+                Port->ms->sender(ep->fd_ctl, ep->fd_data, (PACKET), (LEN), 
ep->port) == -EWOULDBLOCK) {\
+        if (ep->vdepq_count < ep->vdepq_max) \
+        ep->vdepq_count += vdepq_add(&(ep->vdepq), (PACKET), (LEN), TMPBUF); \
+        if (ep->vdepq_count == 1) mainloop_pollmask_set(ep->fd_data, POLLOUT);\
         } \
+        } \
         })
 #endif
 
@@ -410,14 +422,16 @@
 /* functions for FSTP */
 void port_send_packet(int portno, void *packet, int len)
 {
-       SEND_PACKET_PORT(portv[portno],portno,packet,len);
+       void *tmpbuf=NULL;
+       SEND_PACKET_PORT(portv[portno],portno,packet,len,&tmpbuf);
 }
 
 void portset_send_packet(bitarray portset, void *packet, int len)
 {
        register int i;
+       void *tmpbuf=NULL;
        ba_FORALL(portset,numports,
-                       SEND_PACKET_PORT(portv[i],i,packet,len), i);
+                       SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuf), i);
 }
 
 
@@ -503,6 +517,22 @@
         (struct packet *)((char *)(P)-4); })
 
 
+#ifdef VDE_PQ2
+static int trysendfun(struct endpoint *ep, void *packet, int len)
+{
+       int port=ep->port;
+       return portv[port]->ms->sender(ep->fd_ctl, ep->fd_data, packet, len, 
port);
+}
+
+void handle_out_packet(struct endpoint *ep)
+{
+       //printf("handle_out_packet %d\n",ep->vdepq_count);
+       ep->vdepq_count -= vdepq_try(&(ep->vdepq),ep,trysendfun);
+       if (ep->vdepq_count == 0)
+               mainloop_pollmask_del(ep->fd_data, POLLOUT);
+}
+#endif
+
 void handle_in_packet(struct endpoint *ep,  struct packet *packet, int len)
 {
        int tarport;
@@ -517,9 +547,10 @@
 #endif
                if (pflag & HUB_TAG) { /* this is a HUB */
                        register int i;
+                       void *tmpbuf=NULL;
                        for(i = 1; i < numports; i++)
                                if((i != port) && (portv[i] != NULL))
-                                       SEND_PACKET_PORT(portv[i],i,packet,len);
+                                       
SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuf);
                } else { /* This is a switch, not a HUB! */
                        if (packet->header.proto[0] == 0x81 && 
packet->header.proto[1] == 0x00) {
                                tagged=1;
@@ -560,18 +591,22 @@
                                 * of the same tag-ness, then transform it to 
the other tag-ness for the others*/
                                if (tagged) {
                                        register int i;
+                                       void *tmpbuft=NULL;
+                                       void *tmpbufu=NULL;
                                        ba_FORALL(vlant[vlan].bctag,numports,
-                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
+                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuft);}),i);
                                        packet=TAG2UNTAG(packet,len);
                                        ba_FORALL(vlant[vlan].bcuntag,numports,
-                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
+                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbufu);}),i);
                                } else { /* untagged */
                                        register int i;
+                                       void *tmpbufu=NULL;
+                                       void *tmpbuft=NULL;
                                        ba_FORALL(vlant[vlan].bcuntag,numports,
-                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
+                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbufu);}),i);
                                        packet=UNTAG2TAG(packet,vlan,len);
                                        ba_FORALL(vlant[vlan].bctag,numports,
-                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
+                                                       ({if (i != port) 
SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuft);}),i);
                                }
                        }
                        else {
@@ -580,18 +615,20 @@
                                if (tarport==port)
                                        return; /*do not loop!*/
                                if (tagged) {
+                                       void *tmpbuf=NULL;
                                        if (portv[tarport]->vlanuntag==vlan) { 
/* TAG->UNTAG */
                                                packet = TAG2UNTAG(packet,len);
-                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
+                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
                                        } else {                               
/* TAG->TAG */
-                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
+                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
                                        }
                                } else {
+                                       void *tmpbuf=NULL;
                                        if (portv[tarport]->vlanuntag==vlan) { 
/* UNTAG->UNTAG */
-                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
+                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
                                        } else {                              
/* UNTAG->TAG */
                                                packet = 
UNTAG2TAG(packet,vlan,len);
-                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
+                                               
SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
                                        }
                                }
                        } /* if(BROADCAST) */
@@ -830,9 +867,13 @@
                printoutc(fd," IN:  pkts %10lld          bytes 
%20lld",portv[i]->pktsin,portv[i]->bytesin);
                printoutc(fd," OUT: pkts %10lld          bytes 
%20lld",portv[i]->pktsout,portv[i]->bytesout);
 #endif
-               for (ep=portv[i]->ep; ep != NULL; ep=ep->next) 
+               for (ep=portv[i]->ep; ep != NULL; ep=ep->next) {
                        printoutc(fd,"  -- endpoint ID %04d module %-12s: 
%s",ep->fd_ctl,
                                        
portv[i]->ms->modname,(ep->descr)?ep->descr:"no endpoint description");
+#ifdef VDE_PQ2
+                       printoutc(fd,"              unsent packets: %d max 
%d",ep->vdepq_count,ep->vdepq_max);
+#endif
+               }
                return 0;
        } else
                return ENXIO;

Modified: branches/rd235/vde-2/src/vde_switch/port.h
===================================================================
--- branches/rd235/vde-2/src/vde_switch/port.h  2011-03-27 21:04:28 UTC (rev 
482)
+++ branches/rd235/vde-2/src/vde_switch/port.h  2011-03-28 10:05:45 UTC (rev 
483)
@@ -54,6 +54,10 @@
 
 extern int close_ep(struct endpoint *ep);
 
+#ifdef VDE_PQ2
+extern void handle_out_packet(struct endpoint *ep);
+#endif
+
 extern void handle_in_packet(struct endpoint *ep, struct packet *packet, int 
len);
 
 extern bitarray validvlan;

Modified: branches/rd235/vde-2/src/vde_switch/tuntap.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/tuntap.c        2011-03-27 21:04:28 UTC 
(rev 482)
+++ branches/rd235/vde-2/src/vde_switch/tuntap.c        2011-03-28 10:05:45 UTC 
(rev 483)
@@ -57,39 +57,41 @@
        int n;
 
        n = len - write(fd_ctl, packet, len);
-       if(n){
+       if(n > len){
                int rv=errno;
-#ifndef VDE_PQ
-               if(errno != EAGAIN && errno != EWOULDBLOCK) 
+               if(rv != EAGAIN && rv != EWOULDBLOCK) 
                        printlog(LOG_WARNING,"send_tap port %d: 
%s",port,strerror(errno));
-#endif
-               if (n > len)
-                       return -rv;
                else
-                       return n;
+                       rv=EWOULDBLOCK;
+               return -rv;
        }
-       return 0;
+       return n;
 }
 
 static void handle_io(unsigned char type,int fd,int revents,void *private_data)
 {
        struct endpoint *ep=private_data;
-       struct bipacket packet;
-       int len=read(fd, &(packet.p), sizeof(struct packet));
+#ifdef VDE_PQ2
+       if (revents & POLLOUT) 
+               handle_out_packet(ep);
+#endif
+       if (revents & POLLIN) {
+               struct bipacket packet;
+               int len=read(fd, &(packet.p), sizeof(struct packet));
 
-       if(len < 0){
-               if(errno != EAGAIN && errno != EWOULDBLOCK) 
-                       printlog(LOG_WARNING,"Reading tap data: 
%s",strerror(errno));
+               if(len < 0){
+                       if(errno != EAGAIN && errno != EWOULDBLOCK) 
+                               printlog(LOG_WARNING,"Reading tap data: 
%s",strerror(errno));
+               }
+               else if(len == 0) {
+                       if(errno != EAGAIN && errno != EWOULDBLOCK) 
+                               printlog(LOG_WARNING,"EOF tap data port: 
%s",strerror(errno));
+                       /* close tap! */
+               } else if (len >= ETH_HEADER_SIZE)
+                       handle_in_packet(ep, &(packet.p), len);
        }
-       else if(len == 0) {
-               if(errno != EAGAIN && errno != EWOULDBLOCK) 
-                       printlog(LOG_WARNING,"EOF tap data port: 
%s",strerror(errno));
-               /* close tap! */
-       } else if (len >= ETH_HEADER_SIZE)
-               handle_in_packet(ep, &(packet.p), len);
 }
 
-
 static void cleanup(unsigned char type,int fd,void *private_data)
 {
        if (fd >= 0)
@@ -170,11 +172,9 @@
                close(fd);
                return(-1);
        }
-#ifdef VDE_PQ
        /* tuntap should be "fast", but if there is a packetq we can manage
                 a tuntap which is "not fast enough" */
        fcntl(fd, F_SETFL, O_NONBLOCK);
-#endif
        return(fd);
 }
 #endif

Modified: branches/rd235/vde-2/src/vde_switch/vde_switch.c
===================================================================
--- branches/rd235/vde-2/src/vde_switch/vde_switch.c    2011-03-27 21:04:28 UTC 
(rev 482)
+++ branches/rd235/vde-2/src/vde_switch/vde_switch.c    2011-03-28 10:05:45 UTC 
(rev 483)
@@ -32,10 +32,7 @@
 #include <vde.h>
 #include <vdecommon.h>
 
-#ifdef VDE_PQ
-#include "packetq.h"
 #include <poll.h>
-#endif
 
 static struct swmodule *swmh;
 
@@ -236,21 +233,25 @@
 
 short mainloop_pollmask_get(int fd)
 {
+       if (fds[fdperm[fd]].fd != fd) printf("PERMUTATION ERROR %d 
%d\n",fds[fdperm[fd]].fd,fd);
        return fds[fdperm[fd]].events;
 }
 
 void mainloop_pollmask_add(int fd, short events)
 {
+       if (fds[fdperm[fd]].fd != fd) printf("PERMUTATION ERROR %d 
%d\n",fds[fdperm[fd]].fd,fd);
        fds[fdperm[fd]].events |= events;
 }
 
 void mainloop_pollmask_del(int fd, short events)
 {
+       if (fds[fdperm[fd]].fd != fd) printf("PERMUTATION ERROR %d 
%d\n",fds[fdperm[fd]].fd,fd);
        fds[fdperm[fd]].events &= ~events;
 }
 
 void mainloop_pollmask_set(int fd, short events)
 {
+       if (fds[fdperm[fd]].fd != fd) printf("PERMUTATION ERROR %d 
%d\n",fds[fdperm[fd]].fd,fd);
        fds[fdperm[fd]].events = events;
 }
 
@@ -259,15 +260,7 @@
        time_t now;
        register int n,i;
        while(1) {
-#ifdef VDE_PQ
-#ifdef VDE_PQ_PPOLL
-               n=ppoll(fds,nfds,packetq_timeout,NULL);
-#else
-               n=poll(fds,nfds,packetq_timeout);
-#endif
-#else
                n=poll(fds,nfds,-1);
-#endif
                now=qtime();
                if(n < 0){ 
                        if(errno != EINTR)
@@ -300,10 +293,6 @@
                                }
 #endif
                        }
-#ifdef VDE_PQ
-                       if (packetq_timeout > 0)
-                               packetq_try();
-#endif
                }
        }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
vde-users mailing list
vde-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vde-users

Reply via email to