From patchwork Tue Nov 24 11:19:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Shanmugam X-Patchwork-Id: 548009 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3A7A214030F for ; Tue, 24 Nov 2015 22:19:33 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id C7E91108A4; Tue, 24 Nov 2015 03:19:24 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 9C26A108A1 for ; Tue, 24 Nov 2015 03:19:23 -0800 (PST) Received: from bar3.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 227FA161A45 for ; Tue, 24 Nov 2015 04:19:23 -0700 (MST) X-ASG-Debug-ID: 1448363962-03dd7b46452c6a00001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar3.cudamail.com with ESMTP id eQ0ceQr4BnU1McfD (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 24 Nov 2015 04:19:22 -0700 (MST) X-Barracuda-Envelope-From: bschanmu@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 24 Nov 2015 11:19:12 -0000 Received-SPF: pass (mx3-pf1.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id A21DC4E for ; Tue, 24 Nov 2015 11:19:11 +0000 (UTC) Received: from anbu-ltp.redhat.com (ovpn-113-32.phx2.redhat.com [10.3.113.32]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAOBJ3An019633; Tue, 24 Nov 2015 06:19:09 -0500 X-CudaMail-Envelope-Sender: bschanmu@redhat.com From: bschanmu@redhat.com To: dev@openvswitch.org X-CudaMail-MID: CM-V1-1123005628 X-CudaMail-DTE: 112415 X-CudaMail-Originating-IP: 209.132.183.28 Date: Tue, 24 Nov 2015 16:49:00 +0530 X-ASG-Orig-Subj: [##CM-V1-1123005628##][PATCH v4 1/4] ovn: Dedicated connection handler for packet-ins Message-Id: <1448363942-9857-2-git-send-email-bschanmu@redhat.com> In-Reply-To: <1448363942-9857-1-git-send-email-bschanmu@redhat.com> References: <1448363942-9857-1-git-send-email-bschanmu@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-GBUdb-Analysis: 0, 209.132.183.28, Ugly c=0.25607 p=0 Source Normal X-MessageSniffer-Rules: 0-0-0-17208-c X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1448363962 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, NO_REAL_NAME, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.24677 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 NO_REAL_NAME From: does not include a real name 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Subject: [ovs-dev] [PATCH v4 1/4] ovn: Dedicated connection handler for packet-ins X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" This patch opens and maintains a new connection that is dedicated to monitor the packet-ins for br-int. Signed-off-by: Babu Shanmugam --- ovn/controller/automake.mk | 2 + ovn/controller/ovn-controller.c | 6 ++ ovn/controller/pinctrl.c | 177 ++++++++++++++++++++++++++++++++++++++++ ovn/controller/pinctrl.h | 34 ++++++++ 4 files changed, 219 insertions(+) create mode 100644 ovn/controller/pinctrl.c create mode 100644 ovn/controller/pinctrl.h diff --git a/ovn/controller/automake.mk b/ovn/controller/automake.mk index fec9bf1..cadfa9c 100644 --- a/ovn/controller/automake.mk +++ b/ovn/controller/automake.mk @@ -10,6 +10,8 @@ ovn_controller_ovn_controller_SOURCES = \ ovn/controller/lflow.h \ ovn/controller/ofctrl.c \ ovn/controller/ofctrl.h \ + ovn/controller/pinctrl.c \ + ovn/controller/pinctrl.h \ ovn/controller/patch.c \ ovn/controller/patch.h \ ovn/controller/ovn-controller.c \ diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index 3f29b25..02ecb3e 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -41,6 +41,7 @@ #include "util.h" #include "ofctrl.h" +#include "pinctrl.h" #include "binding.h" #include "chassis.h" #include "encaps.h" @@ -223,6 +224,7 @@ main(int argc, char *argv[]) sbrec_init(); ofctrl_init(); + pinctrl_init(); lflow_init(); /* Connect to OVS OVSDB instance. We do not monitor all tables by @@ -292,6 +294,8 @@ main(int argc, char *argv[]) if (br_int) { enum mf_field_id mff_ovn_geneve = ofctrl_run(br_int); + pinctrl_run(&ctx, br_int); + struct hmap flow_table = HMAP_INITIALIZER(&flow_table); lflow_run(&ctx, &flow_table, &ct_zones); if (chassis_id) { @@ -314,6 +318,7 @@ main(int argc, char *argv[]) if (br_int) { ofctrl_wait(); + pinctrl_wait(); } poll_block(); if (should_service_stop()) { @@ -351,6 +356,7 @@ main(int argc, char *argv[]) unixctl_server_destroy(unixctl); lflow_destroy(); ofctrl_destroy(); + pinctrl_destroy(); simap_destroy(&ct_zones); diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c new file mode 100644 index 0000000..7b7fe49 --- /dev/null +++ b/ovn/controller/pinctrl.c @@ -0,0 +1,177 @@ + +/* Copyright (c) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "dirs.h" +#include "pinctrl.h" +#include "ofp-msgs.h" +#include "ofp-print.h" +#include "ofp-util.h" +#include "rconn.h" +#include "openvswitch/vlog.h" +#include "socket-util.h" +#include "vswitch-idl.h" + +VLOG_DEFINE_THIS_MODULE(pinctrl); + +/* OpenFlow connection to the switch. */ +static struct rconn *swconn; + +/* Last seen sequence number for 'swconn'. When this differs from + * rconn_get_connection_seqno(rconn), 'swconn' has reconnected. */ +static unsigned int conn_seq_no; + +void +pinctrl_init(void) +{ + swconn = rconn_create(5, 0, DSCP_DEFAULT, 0xF); + conn_seq_no = 0; +} + +static ovs_be32 +queue_msg(struct ofpbuf *msg) +{ + const struct ofp_header *oh = msg->data; + ovs_be32 xid = oh->xid; + + rconn_send(swconn, msg, NULL); + return xid; +} + +static void +get_switch_config(struct rconn *swconn) +{ + struct ofpbuf *request; + + request = ofpraw_alloc(OFPRAW_OFPT_GET_CONFIG_REQUEST, + rconn_get_version(swconn), 0); + queue_msg(request); +} + +static void +set_switch_config(struct rconn *swconn, const struct ofp_switch_config *config) +{ + struct ofpbuf *request; + + request = + ofpraw_alloc(OFPRAW_OFPT_SET_CONFIG, rconn_get_version(swconn), 0); + ofpbuf_put(request, config, sizeof *config); + + queue_msg(request); +} + +static void +process_packet_in(struct controller_ctx *ctx OVS_UNUSED, + const struct ofp_header *msg) +{ + struct ofputil_packet_in pin; + + if (ofputil_decode_packet_in(&pin, msg) != 0) { + return; + } + if (pin.reason != OFPR_ACTION) { + return; + } + + /* XXX : process the received packet */ +} + +static void +pinctrl_recv(struct controller_ctx *ctx, const struct ofp_header *oh, + enum ofptype type) +{ + if (type == OFPTYPE_ECHO_REQUEST) { + queue_msg(make_echo_reply(oh)); + } else if (type == OFPTYPE_GET_CONFIG_REPLY) { + struct ofpbuf rq_buf; + struct ofpbuf *spif; + struct ofp_switch_config *config_, config; + + ofpbuf_use_const(&rq_buf, oh, ntohs(oh->length)); + config_ = ofpbuf_pull(&rq_buf, sizeof *config_); + config = *config_; + config.miss_send_len = htons(UINT16_MAX); + set_switch_config(swconn, &config); + spif = ofputil_make_set_packet_in_format(rconn_get_version(swconn), + NXPIF_NXM); + queue_msg(spif); + } else if (type == OFPTYPE_PACKET_IN) { + process_packet_in(ctx, oh); + } else if (type != OFPTYPE_ECHO_REPLY && type != OFPTYPE_BARRIER_REPLY) { + if (VLOG_IS_DBG_ENABLED()) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300); + + char *s = ofp_to_string(oh, ntohs(oh->length), 2); + + VLOG_DBG_RL(&rl, "OpenFlow packet ignored: %s", s); + free(s); + } + } +} + +void +pinctrl_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int) +{ + if (br_int) { + char *target; + + target = xasprintf("unix:%s/%s.mgmt", ovs_rundir(), br_int->name); + if (strcmp(target, rconn_get_target(swconn))) { + VLOG_INFO("%s: connecting to switch", target); + rconn_connect(swconn, target, target); + } + free(target); + } else { + rconn_disconnect(swconn); + } + + rconn_run(swconn); + + if (!rconn_is_connected(swconn)) { + return; + } + + if (conn_seq_no != rconn_get_connection_seqno(swconn)) { + get_switch_config(swconn); + conn_seq_no = rconn_get_connection_seqno(swconn); + } + + struct ofpbuf *msg = rconn_recv(swconn); + + if (!msg) { + return; + } + + const struct ofp_header *oh = msg->data; + enum ofptype type; + + ofptype_decode(&type, oh); + pinctrl_recv(ctx, oh, type); + ofpbuf_delete(msg); +} + +void +pinctrl_wait(void) +{ + rconn_run_wait(swconn); + rconn_recv_wait(swconn); +} + +void +pinctrl_destroy(void) +{ + rconn_destroy(swconn); +} diff --git a/ovn/controller/pinctrl.h b/ovn/controller/pinctrl.h new file mode 100644 index 0000000..65d5dfe --- /dev/null +++ b/ovn/controller/pinctrl.h @@ -0,0 +1,34 @@ + +/* Copyright (c) 2015 Nicira, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DHCP_H +#define DHCP_H 1 + +#include + +#include "meta-flow.h" + +struct ovsrec_bridge; +struct controller_ctx; + +/* Interface for OVN main loop. */ +void pinctrl_init(void); +void pinctrl_run(struct controller_ctx *ctx, + const struct ovsrec_bridge *br_int); +void pinctrl_wait(void); +void pinctrl_destroy(void); + +#endif /* ovn/dhcp.h */