Author: adrian.chadd
Date: Sun Feb 22 12:35:27 2009
New Revision: 13819

Modified:
    playpen/LUSCA_HEAD_bgp/app/bgptest/bgptest.c

Log:
Copy the hacky, non-keepalive-happy, non-FSM-y test code in here.



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 12:35:27 2009
@@ -48,16 +48,19 @@
  int
  main(int argc, const char *argv[])
  {
-       int fd;
-       const char *host;
-       short port;
-       u_short as_num;
-       u_short hold_time;
+        int fd, r;
+        struct sockaddr_in sa;
+        struct in_addr bgp_id;
+        char buf[4096];
+        int bufofs = 0;
+        int i, len;

+#if 0
        if (argc < 4) {
                printf("Usage: %s <host> <port> <asnum> <hold-time>\n", 
argv[0]);
                exit(1);
        }
+#endif

        iapp_init();
        squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
@@ -65,15 +68,60 @@
        _db_init("ALL,1");
        _db_set_stderr_debug(1);

-       /* Create BGP FSM */
-
-       /* Setup outgoing socket */
-
-       /* Kick off BGP FSM with given FD */
+
+        fd = socket(AF_INET, SOCK_STREAM, 0);
+        assert(fd != -1);
+
+        /* connect to bgp thing */
+        bzero(&sa, sizeof(sa));
+        inet_aton("216.12.163.51", &sa.sin_addr);
+        inet_aton("216.12.163.53", &bgp_id);
+        sa.sin_port = htons(179);
+        sa.sin_len = sizeof(struct sockaddr_in);
+        sa.sin_family = AF_INET;
+        r = connect(fd, (struct sockaddr *) &sa, sizeof(sa));
+        assert(r > -1);
+
+        /* Now, loop over and read messages */
+        /* We'll eventually have to uhm, speak BGP.. */
+        r = bgp_send_hello(fd, 65535, 120, bgp_id);
+
+        printf("ready to read stuff\n");
+
+        while (1) {
+                bzero(buf + bufofs, sizeof(buf) - bufofs);
+                /* XXX should check there's space in the buffer first! */
+                printf("main: space in buf is %d bytes\n", (int)  
sizeof(buf) - bufofs);
+                len = read(fd, buf + bufofs, sizeof(buf) - bufofs);
+                assert(len > 0);
+                bufofs += len;
+                printf("read: %d bytes; bufsize is now %d\n", len, bufofs);
+                i = 0;
+
+                /* loop over; try to handle partial messages */
+                while (i < len) {
+                        printf("looping..\n");
+                        /* Is there enough data here? */
+                        if (! bgp_msg_complete(buf + i, bufofs - i)) {
+                                printf("main: incomplete packet\n");
+                                break;
+                        }
+                        r = bgp_decode_message(fd, buf + i, bufofs - i);
+                        assert(r > 0);
+                        i += r;
+                        printf("main: pkt was %d bytes, i is now %d\n", r,  
i);
+                }
+                /* "consume" the rest of the buffer */
+                memmove(buf, buf + i, sizeof(buf) - i);
+                bufofs -= i;
+                printf("consumed %d bytes; bufsize is now %d\n", i,  
bufofs);
+        }

+#if 0
        while (1) {
                iapp_runonce(60000);
        }
+#endif

        exit(0);
  }

--~--~---------~--~----~------------~-------~--~----~
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