Author: adrian.chadd
Date: Sun Feb 22 16:10:01 2009
New Revision: 13834

Modified:
    playpen/LUSCA_HEAD_bgp/app/bgptest/bgptest.c
    playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c
    playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h

Log:
Flesh out some very hacky keepalive sending logic and equally hacky hold  
timer logic.

This is all bad, and really stresses the point that bgp_read() is a bad  
idea;
it should be replaced with a way of parsing and then handling BGP events,  
so the FSM
can be driven by the bgp_conn code. We can handle that later though..



Modified: playpen/LUSCA_HEAD_bgp/app/bgptest/bgptest.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/app/bgptest/bgptest.c        (original)
+++ playpen/LUSCA_HEAD_bgp/app/bgptest/bgptest.c        Sun Feb 22 16:10:01 2009
@@ -50,10 +50,12 @@
        struct in_addr rem_ip;
        u_short rem_port;
        int fd;
+       int keepalive_event;
  };
  typedef struct _bgp_conn bgp_conn_t;

  void bgp_conn_begin_connect(bgp_conn_t *bc);
+void bgp_conn_close_and_restart(bgp_conn_t *bc);

  CBDATA_TYPE(bgp_conn_t);
  bgp_conn_t *
@@ -82,6 +84,31 @@
  }

  void
+bgp_conn_send_keepalive(void *data)
+{
+       bgp_conn_t *bc = data;
+       int r;
+       int hold_timer;
+
+       /* Do we have valid hold timers for both sides of the connection? If 
so,  
schedule the recurring keepalive msg */
+       /* XXX should really check the state here! */
+
+       /* Hold timer of 0 means "don't ever send a keepalive" (RFC4271, 4.4.) 
*/
+       hold_timer = bgp_get_holdtimer(&bc->bi);
+       if (hold_timer <= 0)
+               return;
+
+       r = bgp_send_keepalive(&bc->bi, bc->fd);
+       if (r <= 0) {
+               bgp_conn_close_and_restart(bc);
+               return;
+       }
+       //eventAdd("bgp keepalive", bgp_conn_send_keepalive, bc, (hold_timer + 
4)  
/ 2, 0);
+       eventAdd("bgp keepalive", bgp_conn_send_keepalive, bc, 5.0, 0);
+
+}
+
+void
  bgp_conn_destroy(bgp_conn_t *bc)
  {
        eventDelete(bgp_conn_connect_wakeup, bc);
@@ -93,7 +120,6 @@
        cbdataFree(bc);
  }

-
  void
  bgp_conn_close_and_restart(bgp_conn_t *bc)
  {
@@ -102,6 +128,10 @@
                bc->fd = -1;
        }
        bgp_close(&bc->bi);
+       if (eventFind(bgp_conn_connect_wakeup, bc))
+               eventDelete(bgp_conn_connect_wakeup, bc);
+       if (eventFind(bgp_conn_send_keepalive, bc))
+       eventDelete(bgp_conn_send_keepalive, bc);
        bgp_conn_connect_sleep(bc);
  }

@@ -118,6 +148,11 @@
                return;
        }
        commSetSelect(fd, COMM_SELECT_READ, bgp_conn_handle_read, data, 0);
+       /* Have we tried sending a keepalive yet? Then try */
+       if (! bc->keepalive_event) {
+               bc->keepalive_event = 1;
+               bgp_conn_send_keepalive(bc);
+       }
  }

  void

Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c  (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.c  Sun Feb 22 16:10:01 2009
@@ -133,3 +133,18 @@
        /* ensure no as path entries exist in the hash! */
  }

+
+int
+bgp_get_holdtimer(bgp_instance_t *bi)
+{
+       if (bi->lcl.hold_timer == -1 || bi->rem.hold_timer == -1)
+               return -1;
+       if (bi->lcl.hold_timer == 0)
+               return bi->rem.hold_timer;
+       if (bi->rem.hold_timer == 0)
+               return bi->lcl.hold_timer;
+
+       if (bi->rem.hold_timer < bi->lcl.hold_timer)
+               return bi->rem.hold_timer;
+       return bi->lcl.hold_timer;
+}

Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h  (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_core.h  Sun Feb 22 16:10:01 2009
@@ -56,5 +56,6 @@
  void bgp_openconfirm(bgp_instance_t *bi);
  int bgp_read(bgp_instance_t *bi, int fd);
  void bgp_close(bgp_instance_t *bi);
+int bgp_get_holdtimer(bgp_instance_t *bi);

  #endif

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to