1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
4 * We are making the OpenFlow specification and associated documentation
5 * (Software) available for public use and benefit with the expectation
6 * that others will use, modify and enhance the Software and contribute
7 * those enhancements back to the community. However, since we would
8 * like to make the Software available for broadest use, with as few
9 * restrictions as possible permission is hereby granted, free of
10 * charge, to any person obtaining a copy of this Software to deal in
11 * the Software under the copyrights without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * The name and trademarks of copyright holder(s) may NOT be used in
30 * advertising or publicity pertaining to the Software or any
31 * derivatives without specific, written prior permission.
35 #include "vconn-provider.h"
39 #include <netinet/in.h>
43 #include "dynamic-string.h"
45 #include "ofp-print.h"
47 #include "openflow/openflow.h"
48 #include "poll-loop.h"
52 #define THIS_MODULE VLM_vconn
55 /* State of an active vconn.*/
57 /* This is the ordinary progression of states. */
58 VCS_CONNECTING, /* Underlying vconn is not connected. */
59 VCS_SEND_HELLO, /* Waiting to send OFPT_HELLO message. */
60 VCS_RECV_HELLO, /* Waiting to receive OFPT_HELLO message. */
61 VCS_CONNECTED, /* Connection established. */
63 /* These states are entered only when something goes wrong. */
64 VCS_SEND_ERROR, /* Sending OFPT_ERROR message. */
65 VCS_DISCONNECTED /* Connection failed or connection closed. */
68 static struct vconn_class *vconn_classes[] = {
79 static struct pvconn_class *pvconn_classes[] = {
87 /* High rate limit because most of the rate-limiting here is individual
88 * OpenFlow messages going over the vconn. If those are enabled then we
89 * really need to see them. */
90 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(600, 600);
92 static int do_recv(struct vconn *, struct ofpbuf **);
93 static int do_send(struct vconn *, struct ofpbuf *);
95 /* Check the validity of the vconn class structures. */
97 check_vconn_classes(void)
102 for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
103 struct vconn_class *class = vconn_classes[i];
104 assert(class->name != NULL);
105 assert(class->open != NULL);
106 if (class->close || class->recv || class->send || class->wait) {
107 assert(class->close != NULL);
108 assert(class->recv != NULL);
109 assert(class->send != NULL);
110 assert(class->wait != NULL);
112 /* This class delegates to another one. */
116 for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
117 struct pvconn_class *class = pvconn_classes[i];
118 assert(class->name != NULL);
119 assert(class->listen != NULL);
120 if (class->close || class->accept || class->wait) {
121 assert(class->close != NULL);
122 assert(class->accept != NULL);
123 assert(class->wait != NULL);
125 /* This class delegates to another one. */
131 /* Prints information on active (if 'active') and passive (if 'passive')
132 * connection methods supported by the vconn. If 'bootstrap' is true, also
133 * advertises options to bootstrap the CA certificate. */
135 vconn_usage(bool active, bool passive, bool bootstrap UNUSED)
137 /* Really this should be implemented via callbacks into the vconn
138 * providers, but that seems too heavy-weight to bother with at the
143 printf("Active OpenFlow connection methods:\n");
146 "local datapath DP_IDX\n");
148 printf(" tcp:HOST[:PORT] "
149 "PORT (default: %d) on remote TCP HOST\n", OFP_TCP_PORT);
151 printf(" ssl:HOST[:PORT] "
152 "SSL PORT (default: %d) on remote HOST\n", OFP_SSL_PORT);
154 printf(" unix:FILE Unix domain socket named FILE\n");
158 printf("Passive OpenFlow connection methods:\n");
159 printf(" ptcp:[PORT] "
160 "listen to TCP PORT (default: %d)\n",
163 printf(" pssl:[PORT] "
164 "listen for SSL on PORT (default: %d)\n",
167 printf(" punix:FILE "
168 "listen on Unix domain socket FILE\n");
172 printf("PKI configuration (required to use SSL):\n"
173 " -p, --private-key=FILE file with private key\n"
174 " -c, --certificate=FILE file with certificate for private key\n"
175 " -C, --ca-cert=FILE file with peer CA certificate\n");
177 printf(" --bootstrap-ca-cert=FILE file with peer CA certificate "
178 "to read or create\n");
183 /* Attempts to connect to an OpenFlow device. 'name' is a connection name in
184 * the form "TYPE:ARGS", where TYPE is an active vconn class's name and ARGS
185 * are vconn class-specific.
187 * The vconn will automatically negotiate an OpenFlow protocol version
188 * acceptable to both peers on the connection. The version negotiated will be
189 * no lower than 'min_version' and no higher than OFP_VERSION.
191 * Returns 0 if successful, otherwise a positive errno value. If successful,
192 * stores a pointer to the new connection in '*vconnp', otherwise a null
195 vconn_open(const char *name, int min_version, struct vconn **vconnp)
200 check_vconn_classes();
203 prefix_len = strcspn(name, ":");
204 if (prefix_len == strlen(name)) {
207 for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
208 struct vconn_class *class = vconn_classes[i];
209 if (strlen(class->name) == prefix_len
210 && !memcmp(class->name, name, prefix_len)) {
212 char *suffix_copy = xstrdup(name + prefix_len + 1);
213 int retval = class->open(name, suffix_copy, &vconn);
216 assert(vconn->state != VCS_CONNECTING
217 || vconn->class->connect);
218 vconn->min_version = min_version;
228 vconn_open_block(const char *name, int min_version, struct vconn **vconnp)
233 error = vconn_open(name, min_version, &vconn);
234 while (error == EAGAIN) {
235 vconn_connect_wait(vconn);
237 error = vconn_connect(vconn);
238 assert(error != EINPROGRESS);
249 /* Closes 'vconn'. */
251 vconn_close(struct vconn *vconn)
254 char *name = vconn->name;
255 (vconn->class->close)(vconn);
260 /* Returns the name of 'vconn', that is, the string passed to vconn_open(). */
262 vconn_get_name(const struct vconn *vconn)
267 /* Returns the IP address of the peer, or 0 if the peer is not connected over
268 * an IP-based protocol or if its IP address is not yet known. */
270 vconn_get_ip(const struct vconn *vconn)
276 vcs_connecting(struct vconn *vconn)
278 int retval = (vconn->class->connect)(vconn);
279 assert(retval != EINPROGRESS);
281 vconn->state = VCS_SEND_HELLO;
282 } else if (retval != EAGAIN) {
283 vconn->state = VCS_DISCONNECTED;
284 vconn->error = retval;
289 vcs_send_hello(struct vconn *vconn)
294 make_openflow(sizeof(struct ofp_header), OFPT_HELLO, &b);
295 retval = do_send(vconn, b);
297 vconn->state = VCS_RECV_HELLO;
300 if (retval != EAGAIN) {
301 vconn->state = VCS_DISCONNECTED;
302 vconn->error = retval;
308 vcs_recv_hello(struct vconn *vconn)
313 retval = do_recv(vconn, &b);
315 struct ofp_header *oh = b->data;
317 if (oh->type == OFPT_HELLO) {
318 if (b->size > sizeof *oh) {
319 struct ds msg = DS_EMPTY_INITIALIZER;
320 ds_put_format(&msg, "%s: extra-long hello:\n", vconn->name);
321 ds_put_hex_dump(&msg, b->data, b->size, 0, true);
322 VLOG_WARN_RL(&rl, ds_cstr(&msg));
326 vconn->version = MIN(OFP_VERSION, oh->version);
327 if (vconn->version < vconn->min_version) {
328 VLOG_WARN_RL(&rl, "%s: version negotiation failed: we support "
329 "versions 0x%02x to 0x%02x inclusive but peer "
330 "supports no later than version 0x%02"PRIx8,
331 vconn->name, vconn->min_version, OFP_VERSION,
333 vconn->state = VCS_SEND_ERROR;
335 VLOG_DBG("%s: negotiated OpenFlow version 0x%02x "
336 "(we support versions 0x%02x to 0x%02x inclusive, "
337 "peer no later than version 0x%02"PRIx8")",
338 vconn->name, vconn->version, vconn->min_version,
339 OFP_VERSION, oh->version);
340 vconn->state = VCS_CONNECTED;
345 char *s = ofp_to_string(b->data, b->size, 1);
346 VLOG_WARN_RL(&rl, "%s: received message while expecting hello: %s",
354 if (retval != EAGAIN) {
355 vconn->state = VCS_DISCONNECTED;
356 vconn->error = retval;
361 vcs_send_error(struct vconn *vconn)
363 struct ofp_error_msg *error;
368 snprintf(s, sizeof s, "We support versions 0x%02x to 0x%02x inclusive but "
369 "you support no later than version 0x%02"PRIx8".",
370 vconn->min_version, OFP_VERSION, vconn->version);
371 error = make_openflow(sizeof *error, OFPT_ERROR, &b);
372 error->type = htons(OFPET_HELLO_FAILED);
373 error->code = htons(OFPHFC_INCOMPATIBLE);
374 ofpbuf_put(b, s, strlen(s));
375 update_openflow_length(b);
376 retval = do_send(vconn, b);
380 if (retval != EAGAIN) {
381 vconn->state = VCS_DISCONNECTED;
382 vconn->error = retval ? retval : EPROTO;
386 /* Tries to complete the connection on 'vconn', which must be an active
387 * vconn. If 'vconn''s connection is complete, returns 0 if the connection
388 * was successful or a positive errno value if it failed. If the
389 * connection is still in progress, returns EAGAIN. */
391 vconn_connect(struct vconn *vconn)
393 enum vconn_state last_state;
395 assert(vconn->min_version >= 0);
397 last_state = vconn->state;
398 switch (vconn->state) {
400 vcs_connecting(vconn);
404 vcs_send_hello(vconn);
408 vcs_recv_hello(vconn);
415 vcs_send_error(vconn);
418 case VCS_DISCONNECTED:
424 } while (vconn->state != last_state);
429 /* Tries to receive an OpenFlow message from 'vconn', which must be an active
430 * vconn. If successful, stores the received message into '*msgp' and returns
431 * 0. The caller is responsible for destroying the message with
432 * ofpbuf_delete(). On failure, returns a positive errno value and stores a
433 * null pointer into '*msgp'. On normal connection close, returns EOF.
435 * vconn_recv will not block waiting for a packet to arrive. If no packets
436 * have been received, it returns EAGAIN immediately. */
438 vconn_recv(struct vconn *vconn, struct ofpbuf **msgp)
440 int retval = vconn_connect(vconn);
442 retval = do_recv(vconn, msgp);
448 do_recv(struct vconn *vconn, struct ofpbuf **msgp)
452 retval = (vconn->class->recv)(vconn, msgp);
454 struct ofp_header *oh;
456 if (VLOG_IS_DBG_ENABLED()) {
457 char *s = ofp_to_string((*msgp)->data, (*msgp)->size, 1);
458 VLOG_DBG_RL(&rl, "%s: received: %s", vconn->name, s);
462 oh = ofpbuf_at_assert(*msgp, 0, sizeof *oh);
463 if (oh->version != vconn->version
464 && oh->type != OFPT_HELLO
465 && oh->type != OFPT_ERROR
466 && oh->type != OFPT_ECHO_REQUEST
467 && oh->type != OFPT_ECHO_REPLY
468 && oh->type != OFPT_VENDOR)
470 if (vconn->version < 0) {
471 VLOG_ERR_RL(&rl, "%s: received OpenFlow version %02"PRIx8" "
472 "before version negotiation complete",
473 vconn->name, oh->version);
475 VLOG_ERR_RL(&rl, "%s: received OpenFlow version %02"PRIx8" "
477 vconn->name, oh->version, vconn->version);
479 ofpbuf_delete(*msgp);
489 /* Tries to queue 'msg' for transmission on 'vconn', which must be an active
490 * vconn. If successful, returns 0, in which case ownership of 'msg' is
491 * transferred to the vconn. Success does not guarantee that 'msg' has been or
492 * ever will be delivered to the peer, only that it has been queued for
495 * Returns a positive errno value on failure, in which case the caller
496 * retains ownership of 'msg'.
498 * vconn_send will not block. If 'msg' cannot be immediately accepted for
499 * transmission, it returns EAGAIN immediately. */
501 vconn_send(struct vconn *vconn, struct ofpbuf *msg)
503 int retval = vconn_connect(vconn);
505 retval = do_send(vconn, msg);
511 do_send(struct vconn *vconn, struct ofpbuf *msg)
515 assert(msg->size >= sizeof(struct ofp_header));
516 assert(((struct ofp_header *) msg->data)->length == htons(msg->size));
517 if (!VLOG_IS_DBG_ENABLED()) {
518 retval = (vconn->class->send)(vconn, msg);
520 char *s = ofp_to_string(msg->data, msg->size, 1);
521 retval = (vconn->class->send)(vconn, msg);
522 if (retval != EAGAIN) {
523 VLOG_DBG_RL(&rl, "%s: sent (%s): %s",
524 vconn->name, strerror(retval), s);
531 /* Same as vconn_send, except that it waits until 'msg' can be transmitted. */
533 vconn_send_block(struct vconn *vconn, struct ofpbuf *msg)
536 while ((retval = vconn_send(vconn, msg)) == EAGAIN) {
537 vconn_send_wait(vconn);
543 /* Same as vconn_recv, except that it waits until a message is received. */
545 vconn_recv_block(struct vconn *vconn, struct ofpbuf **msgp)
548 while ((retval = vconn_recv(vconn, msgp)) == EAGAIN) {
549 vconn_recv_wait(vconn);
555 /* Waits until a message with a transaction ID matching 'xid' is recived on
556 * 'vconn'. Returns 0 if successful, in which case the reply is stored in
557 * '*replyp' for the caller to examine and free. Otherwise returns a positive
558 * errno value, or EOF, and sets '*replyp' to null.
560 * 'request' is always destroyed, regardless of the return value. */
562 vconn_recv_xid(struct vconn *vconn, uint32_t xid, struct ofpbuf **replyp)
566 struct ofpbuf *reply;
569 error = vconn_recv_block(vconn, &reply);
574 recv_xid = ((struct ofp_header *) reply->data)->xid;
575 if (xid == recv_xid) {
580 VLOG_DBG_RL(&rl, "%s: received reply with xid %08"PRIx32" != expected "
581 "%08"PRIx32, vconn->name, recv_xid, xid);
582 ofpbuf_delete(reply);
586 /* Sends 'request' to 'vconn' and blocks until it receives a reply with a
587 * matching transaction ID. Returns 0 if successful, in which case the reply
588 * is stored in '*replyp' for the caller to examine and free. Otherwise
589 * returns a positive errno value, or EOF, and sets '*replyp' to null.
591 * 'request' is always destroyed, regardless of the return value. */
593 vconn_transact(struct vconn *vconn, struct ofpbuf *request,
594 struct ofpbuf **replyp)
596 uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
600 error = vconn_send_block(vconn, request);
601 ofpbuf_delete(request);
602 return error ? error : vconn_recv_xid(vconn, send_xid, replyp);
606 vconn_wait(struct vconn *vconn, enum vconn_wait_type wait)
608 assert(wait == WAIT_CONNECT || wait == WAIT_RECV || wait == WAIT_SEND);
610 switch (vconn->state) {
627 case VCS_DISCONNECTED:
628 poll_immediate_wake();
631 (vconn->class->wait)(vconn, wait);
635 vconn_connect_wait(struct vconn *vconn)
637 vconn_wait(vconn, WAIT_CONNECT);
641 vconn_recv_wait(struct vconn *vconn)
643 vconn_wait(vconn, WAIT_RECV);
647 vconn_send_wait(struct vconn *vconn)
649 vconn_wait(vconn, WAIT_SEND);
652 /* Attempts to start listening for OpenFlow connections. 'name' is a
653 * connection name in the form "TYPE:ARGS", where TYPE is an passive vconn
654 * class's name and ARGS are vconn class-specific.
656 * Returns 0 if successful, otherwise a positive errno value. If successful,
657 * stores a pointer to the new connection in '*pvconnp', otherwise a null
660 pvconn_open(const char *name, struct pvconn **pvconnp)
665 check_vconn_classes();
668 prefix_len = strcspn(name, ":");
669 if (prefix_len == strlen(name)) {
672 for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
673 struct pvconn_class *class = pvconn_classes[i];
674 if (strlen(class->name) == prefix_len
675 && !memcmp(class->name, name, prefix_len)) {
676 char *suffix_copy = xstrdup(name + prefix_len + 1);
677 int retval = class->listen(name, suffix_copy, pvconnp);
688 /* Closes 'pvconn'. */
690 pvconn_close(struct pvconn *pvconn)
692 if (pvconn != NULL) {
693 char *name = pvconn->name;
694 (pvconn->class->close)(pvconn);
699 /* Tries to accept a new connection on 'pvconn'. If successful, stores the new
700 * connection in '*new_vconn' and returns 0. Otherwise, returns a positive
703 * The new vconn will automatically negotiate an OpenFlow protocol version
704 * acceptable to both peers on the connection. The version negotiated will be
705 * no lower than 'min_version' and no higher than OFP_VERSION.
707 * pvconn_accept() will not block waiting for a connection. If no connection
708 * is ready to be accepted, it returns EAGAIN immediately. */
710 pvconn_accept(struct pvconn *pvconn, int min_version, struct vconn **new_vconn)
712 int retval = (pvconn->class->accept)(pvconn, new_vconn);
716 assert((*new_vconn)->state != VCS_CONNECTING
717 || (*new_vconn)->class->connect);
718 (*new_vconn)->min_version = min_version;
724 pvconn_wait(struct pvconn *pvconn)
726 (pvconn->class->wait)(pvconn);
729 /* Allocates and returns the first byte of a buffer 'openflow_len' bytes long,
730 * containing an OpenFlow header with the given 'type' and a random transaction
731 * id. Stores the new buffer in '*bufferp'. The caller must free the buffer
732 * when it is no longer needed. */
734 make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **bufferp)
736 return make_openflow_xid(openflow_len, type, random_uint32(), bufferp);
739 /* Allocates and returns the first byte of a buffer 'openflow_len' bytes long,
740 * containing an OpenFlow header with the given 'type' and transaction id
741 * 'xid'. Stores the new buffer in '*bufferp'. The caller must free the
742 * buffer when it is no longer needed. */
744 make_openflow_xid(size_t openflow_len, uint8_t type, uint32_t xid,
745 struct ofpbuf **bufferp)
747 struct ofpbuf *buffer;
748 struct ofp_header *oh;
750 assert(openflow_len >= sizeof *oh);
751 assert(openflow_len <= UINT16_MAX);
752 buffer = *bufferp = ofpbuf_new(openflow_len);
753 oh = ofpbuf_put_zeros(buffer, openflow_len);
754 oh->version = OFP_VERSION;
756 oh->length = htons(openflow_len);
761 /* Updates the 'length' field of the OpenFlow message in 'buffer' to
764 update_openflow_length(struct ofpbuf *buffer)
766 struct ofp_header *oh = ofpbuf_at_assert(buffer, 0, sizeof *oh);
767 oh->length = htons(buffer->size);
771 make_add_flow(const struct flow *flow, uint32_t buffer_id,
772 uint16_t idle_timeout, size_t actions_len)
774 struct ofp_flow_mod *ofm;
775 size_t size = sizeof *ofm + actions_len;
776 struct ofpbuf *out = ofpbuf_new(size);
777 ofm = ofpbuf_put_zeros(out, size);
778 ofm->header.version = OFP_VERSION;
779 ofm->header.type = OFPT_FLOW_MOD;
780 ofm->header.length = htons(size);
781 ofm->match.wildcards = htonl(0);
782 ofm->match.in_port = flow->in_port;
783 memcpy(ofm->match.dl_src, flow->dl_src, sizeof ofm->match.dl_src);
784 memcpy(ofm->match.dl_dst, flow->dl_dst, sizeof ofm->match.dl_dst);
785 ofm->match.dl_vlan = flow->dl_vlan;
786 ofm->match.dl_type = flow->dl_type;
787 ofm->match.nw_src = flow->nw_src;
788 ofm->match.nw_dst = flow->nw_dst;
789 ofm->match.nw_proto = flow->nw_proto;
790 ofm->match.tp_src = flow->tp_src;
791 ofm->match.tp_dst = flow->tp_dst;
792 ofm->command = htons(OFPFC_ADD);
793 ofm->idle_timeout = htons(idle_timeout);
794 ofm->hard_timeout = htons(OFP_FLOW_PERMANENT);
795 ofm->buffer_id = htonl(buffer_id);
800 make_add_simple_flow(const struct flow *flow,
801 uint32_t buffer_id, uint16_t out_port,
802 uint16_t idle_timeout)
804 struct ofp_action_output *oao;
805 struct ofpbuf *buffer = make_add_flow(flow, buffer_id, idle_timeout,
807 struct ofp_flow_mod *ofm = buffer->data;
808 oao = (struct ofp_action_output *)&ofm->actions[0];
809 oao->type = htons(OFPAT_OUTPUT);
810 oao->len = htons(sizeof *oao);
811 oao->port = htons(out_port);
816 make_unbuffered_packet_out(const struct ofpbuf *packet,
817 uint16_t in_port, uint16_t out_port)
819 struct ofp_packet_out *opo;
820 struct ofp_action_output *oao;
821 size_t size = sizeof *opo + sizeof *oao;
822 struct ofpbuf *out = ofpbuf_new(size + packet->size);
824 opo = ofpbuf_put_zeros(out, size);
825 opo->header.version = OFP_VERSION;
826 opo->header.type = OFPT_PACKET_OUT;
827 opo->buffer_id = htonl(UINT32_MAX);
828 opo->in_port = htons(in_port);
830 oao = (struct ofp_action_output *)&opo->actions[0];
831 oao->type = htons(OFPAT_OUTPUT);
832 oao->len = htons(sizeof *oao);
833 oao->port = htons(out_port);
835 opo->actions_len = htons(sizeof *oao);
837 ofpbuf_put(out, packet->data, packet->size);
838 update_openflow_length(out);
843 make_buffered_packet_out(uint32_t buffer_id,
844 uint16_t in_port, uint16_t out_port)
846 struct ofp_packet_out *opo;
847 struct ofp_action_output *oao;
848 size_t size = sizeof *opo + sizeof *oao;
849 struct ofpbuf *out = ofpbuf_new(size);
850 opo = ofpbuf_put_zeros(out, size);
851 opo->header.version = OFP_VERSION;
852 opo->header.type = OFPT_PACKET_OUT;
853 opo->header.length = htons(size);
854 opo->buffer_id = htonl(buffer_id);
855 opo->in_port = htons(in_port);
857 oao = (struct ofp_action_output *)&opo->actions[0];
858 oao->type = htons(OFPAT_OUTPUT);
859 oao->len = htons(sizeof *oao);
860 oao->port = htons(out_port);
862 opo->actions_len = htons(sizeof *oao);
866 /* Creates and returns an OFPT_ECHO_REQUEST message with an empty payload. */
868 make_echo_request(void)
870 struct ofp_header *rq;
871 struct ofpbuf *out = ofpbuf_new(sizeof *rq);
872 rq = ofpbuf_put_uninit(out, sizeof *rq);
873 rq->version = OFP_VERSION;
874 rq->type = OFPT_ECHO_REQUEST;
875 rq->length = htons(sizeof *rq);
880 /* Creates and returns an OFPT_ECHO_REPLY message matching the
881 * OFPT_ECHO_REQUEST message in 'rq'. */
883 make_echo_reply(const struct ofp_header *rq)
885 size_t size = ntohs(rq->length);
886 struct ofpbuf *out = ofpbuf_new(size);
887 struct ofp_header *reply = ofpbuf_put(out, rq, size);
888 reply->type = OFPT_ECHO_REPLY;
893 vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status,
894 uint32_t ip, const char *name)
896 vconn->class = class;
897 vconn->state = (connect_status == EAGAIN ? VCS_CONNECTING
898 : !connect_status ? VCS_SEND_HELLO
900 vconn->error = connect_status;
902 vconn->min_version = -1;
904 vconn->name = xstrdup(name);
908 pvconn_init(struct pvconn *pvconn, struct pvconn_class *class,
911 pvconn->class = class;
912 pvconn->name = xstrdup(name);