From: Ben Pfaff Date: Mon, 31 Mar 2008 16:53:11 +0000 (-0700) Subject: Better abstract controller_connection. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbb2acb53ea7442f44ad4b9609579319caeb4503;p=openvswitch Better abstract controller_connection. --- diff --git a/switch/controller.c b/switch/controller.c index 57e8b9e6..d8152311 100644 --- a/switch/controller.c +++ b/switch/controller.c @@ -43,16 +43,27 @@ #define THIS_MODULE VLM_controller_connection #include "vlog.h" -void -controller_init(struct controller_connection *cc, - const char *name, bool reliable) +struct controller_connection { + bool reliable; + const char *name; + struct vconn *vconn; + bool connected; + struct queue txq; + time_t backoff_deadline; + int backoff; +}; + +struct controller_connection * +controller_new(const char *name, bool reliable) { + struct controller_connection *cc = xmalloc(sizeof *cc); cc->reliable = reliable; cc->name = name; cc->vconn = NULL; queue_init(&cc->txq); cc->backoff_deadline = 0; cc->backoff = 0; + return cc; } static int diff --git a/switch/controller.h b/switch/controller.h index c3108e41..6c38dd11 100644 --- a/switch/controller.h +++ b/switch/controller.h @@ -38,20 +38,7 @@ #include #include -struct datapath; - -struct controller_connection { - bool reliable; - const char *name; - struct vconn *vconn; - bool connected; - struct queue txq; - time_t backoff_deadline; - int backoff; -}; - -void controller_init(struct controller_connection *, - const char *name, bool reliable); +struct controller_connection *controller_new(const char *name, bool reliable); void controller_run(struct controller_connection *); void controller_run_wait(struct controller_connection *); void controller_connect(struct controller_connection *); diff --git a/switch/switch.c b/switch/switch.c index cbdc9654..b36d9486 100644 --- a/switch/switch.c +++ b/switch/switch.c @@ -66,7 +66,7 @@ static void add_ports(struct datapath *dp, char *port_list); int main(int argc, char *argv[]) { - struct controller_connection cc; + struct controller_connection *cc; int error; set_program_name(argv[0]); @@ -78,8 +78,8 @@ main(int argc, char *argv[]) fatal(0, "missing controller argument; use --help for usage"); } - controller_init(&cc, argv[optind], reliable); - error = dp_new(&dp, dpid, &cc); + cc = controller_new(argv[optind], reliable); + error = dp_new(&dp, dpid, cc); if (error) { fatal(error, "could not create datapath"); } @@ -95,11 +95,11 @@ main(int argc, char *argv[]) for (;;) { dp_run(dp); fwd_run(dp); - controller_run(&cc); + controller_run(cc); dp_wait(dp); fwd_run_wait(dp); - controller_run_wait(&cc); + controller_run_wait(cc); poll_block(); }