From patchwork Fri Oct 23 07:45:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Shanmugam X-Patchwork-Id: 534815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 1752414131D for ; Fri, 23 Oct 2015 18:45:43 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 1A13A10A87; Fri, 23 Oct 2015 00:45:43 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 258B310A66 for ; Fri, 23 Oct 2015 00:45:42 -0700 (PDT) Received: from bar3.cudamail.com (bar1 [192.168.15.1]) by mx3v1.cudamail.com (Postfix) with ESMTP id A8585618A01 for ; Fri, 23 Oct 2015 01:45:41 -0600 (MDT) X-ASG-Debug-ID: 1445586340-03dd7b10651ff850001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar3.cudamail.com with ESMTP id jjqNpyXdhbldY1LH (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 23 Oct 2015 01:45:40 -0600 (MDT) X-Barracuda-Envelope-From: bschanmu@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 23 Oct 2015 07:45:30 -0000 Received-SPF: pass (mx3-pf2.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-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 46810FA9EB for ; Fri, 23 Oct 2015 07:45:29 +0000 (UTC) Received: from [10.3.113.5] ([10.3.113.5]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9N7jQE3016283 for ; Fri, 23 Oct 2015 03:45:27 -0400 To: dev@openvswitch.org X-CudaMail-Envelope-Sender: bschanmu@redhat.com From: Babu Shanmugam X-CudaMail-MID: CM-V2-1022001754 X-CudaMail-DTE: 102315 X-CudaMail-Originating-IP: 209.132.183.28 Message-ID: <5629E596.20503@redhat.com> X-ASG-Orig-Subj: [##CM-V2-1022001754##][PATCH 2/4] ovn: Passive connection handlers for the controller for br-int Date: Fri, 23 Oct 2015 13:15:26 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-GBUdb-Analysis: 0, 209.132.183.28, Ugly c=0.382685 p=-0.0731707 Source Normal X-MessageSniffer-Rules: 0-0-0-20588-c X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1445586340 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.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=3.0 tests=BSF_SC5_MJ1963, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.23745 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 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 2/4] ovn: Passive connection handlers for the controller for br-int 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: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" This patch handles and maintains the passive connection for br-int Signed-off-by: Babu Shanmugam --- ovn/controller/automake.mk | 2 + ovn/controller/ofcontroller.c | 231 ++++++++++++++++++++++++++++++++++++++++ ovn/controller/ofcontroller.h | 33 ++++++ ovn/controller/ovn-controller.c | 4 + 4 files changed, 270 insertions(+) create mode 100644 ovn/controller/ofcontroller.c create mode 100644 ovn/controller/ofcontroller.h diff --git a/ovn/controller/automake.mk b/ovn/controller/automake.mk index fec9bf1..9702b11 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/ofcontroller.c \ + ovn/controller/ofcontroller.h \ ovn/controller/patch.c \ ovn/controller/patch.h \ ovn/controller/ovn-controller.c \ diff --git a/ovn/controller/ofcontroller.c b/ovn/controller/ofcontroller.c new file mode 100644 index 0000000..8a6c124 --- /dev/null +++ b/ovn/controller/ofcontroller.c @@ -0,0 +1,231 @@ + +/* 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 "dp-packet.h" +#include "lflow.h" +#include "ofctrl.h" +#include "ofp-msgs.h" +#include "ofp-util.h" +#include "ofp-actions.h" +#include "ofp-version-opt.h" +#include "openflow/openflow.h" +#include "openvswitch/vconn.h" +#include "openvswitch/vlog.h" +#include "ovn-controller.h" +#include "physical.h" +#include "rconn.h" +#include "socket-util.h" +#include "vswitch-idl.h" +#include "ofcontroller.h" + +VLOG_DEFINE_THIS_MODULE(ofcontroller); + +/* Passive connection for the controller */ +struct pvconn *pvconn; + +/* Remote connection from the switch */ +struct rconn *rconn = NULL; + +void +ofcontroller_init(char const *sock_path) +{ + char *proto = xasprintf("punix:%s", sock_path); + + pvconn_open(proto, 0, 0, &pvconn); + free(proto); +} + +static void +process_packet_in(struct controller_ctx *ctx OVS_UNUSED, + 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 +process_packet(struct controller_ctx *ctx, struct ofpbuf *msg) +{ + enum ofptype type; + struct ofpbuf b; + + b = *msg; + if (ofptype_pull(&type, &b)) { + return; + } + switch (type) { + case OFPTYPE_HELLO: + { + uint32_t allowed_versions; + + ofputil_decode_hello(msg->data, &allowed_versions); + /* XXX: Negotiate */ + break; + } + case OFPTYPE_ECHO_REQUEST: + { + struct ofpbuf *r = make_echo_reply(msg->data); + + rconn_send(rconn, r, NULL); + break; + } + case OFPTYPE_FEATURES_REPLY: + /* XXX: Finish this */ + break; + case OFPTYPE_PACKET_IN: + process_packet_in(ctx, msg->data); + break; + case OFPTYPE_FLOW_REMOVED: + case OFPTYPE_ERROR: + case OFPTYPE_ECHO_REPLY: + case OFPTYPE_FEATURES_REQUEST: + case OFPTYPE_GET_CONFIG_REQUEST: + case OFPTYPE_GET_CONFIG_REPLY: + case OFPTYPE_SET_CONFIG: + case OFPTYPE_PORT_STATUS: + case OFPTYPE_PACKET_OUT: + case OFPTYPE_FLOW_MOD: + case OFPTYPE_GROUP_MOD: + case OFPTYPE_PORT_MOD: + case OFPTYPE_TABLE_MOD: + case OFPTYPE_BARRIER_REQUEST: + case OFPTYPE_BARRIER_REPLY: + case OFPTYPE_QUEUE_GET_CONFIG_REQUEST: + case OFPTYPE_QUEUE_GET_CONFIG_REPLY: + case OFPTYPE_DESC_STATS_REQUEST: + case OFPTYPE_DESC_STATS_REPLY: + case OFPTYPE_FLOW_STATS_REQUEST: + case OFPTYPE_FLOW_STATS_REPLY: + case OFPTYPE_AGGREGATE_STATS_REQUEST: + case OFPTYPE_AGGREGATE_STATS_REPLY: + case OFPTYPE_TABLE_STATS_REQUEST: + case OFPTYPE_TABLE_STATS_REPLY: + case OFPTYPE_PORT_STATS_REQUEST: + case OFPTYPE_PORT_STATS_REPLY: + case OFPTYPE_QUEUE_STATS_REQUEST: + case OFPTYPE_QUEUE_STATS_REPLY: + case OFPTYPE_PORT_DESC_STATS_REQUEST: + case OFPTYPE_PORT_DESC_STATS_REPLY: + case OFPTYPE_ROLE_REQUEST: + case OFPTYPE_ROLE_REPLY: + case OFPTYPE_ROLE_STATUS: + case OFPTYPE_REQUESTFORWARD: + case OFPTYPE_SET_FLOW_FORMAT: + case OFPTYPE_FLOW_MOD_TABLE_ID: + case OFPTYPE_SET_PACKET_IN_FORMAT: + case OFPTYPE_FLOW_AGE: + case OFPTYPE_SET_CONTROLLER_ID: + case OFPTYPE_FLOW_MONITOR_STATS_REQUEST: + case OFPTYPE_FLOW_MONITOR_STATS_REPLY: + case OFPTYPE_FLOW_MONITOR_CANCEL: + case OFPTYPE_FLOW_MONITOR_PAUSED: + case OFPTYPE_FLOW_MONITOR_RESUMED: + case OFPTYPE_GET_ASYNC_REQUEST: + case OFPTYPE_GET_ASYNC_REPLY: + case OFPTYPE_SET_ASYNC_CONFIG: + case OFPTYPE_METER_MOD: + case OFPTYPE_GROUP_STATS_REQUEST: + case OFPTYPE_GROUP_STATS_REPLY: + case OFPTYPE_GROUP_DESC_STATS_REQUEST: + case OFPTYPE_GROUP_DESC_STATS_REPLY: + case OFPTYPE_GROUP_FEATURES_STATS_REQUEST: + case OFPTYPE_GROUP_FEATURES_STATS_REPLY: + case OFPTYPE_METER_STATS_REQUEST: + case OFPTYPE_METER_STATS_REPLY: + case OFPTYPE_METER_CONFIG_STATS_REQUEST: + case OFPTYPE_METER_CONFIG_STATS_REPLY: + case OFPTYPE_METER_FEATURES_STATS_REQUEST: + case OFPTYPE_METER_FEATURES_STATS_REPLY: + case OFPTYPE_TABLE_FEATURES_STATS_REQUEST: + case OFPTYPE_TABLE_FEATURES_STATS_REPLY: + case OFPTYPE_TABLE_DESC_REQUEST: + case OFPTYPE_TABLE_DESC_REPLY: + case OFPTYPE_BUNDLE_CONTROL: + case OFPTYPE_BUNDLE_ADD_MESSAGE: + case OFPTYPE_NXT_GENEVE_TABLE_MOD: + case OFPTYPE_NXT_GENEVE_TABLE_REQUEST: + case OFPTYPE_NXT_GENEVE_TABLE_REPLY: + default: + break; + } +} + +static void +send_hello_packet(struct rconn *rconn) +{ + struct ofpbuf *ofbuf; + + ofbuf = ofputil_encode_hello(rconn_get_allowed_versions(rconn)); + rconn_send(rconn, ofbuf, NULL); +} + +enum ofputil_protocol +ofcontroller_ofp_proto(void) +{ + enum ofp_version version; + + version = rconn_get_version(rconn); + return ofputil_protocol_from_ofp_version(version); +} + +void +ofcontroller_run(struct controller_ctx *ctx, + const struct ovsrec_bridge *br_int) +{ + struct ofpbuf *msg; + int retval; + struct vconn *new_vconn = NULL; + + if (br_int) { + retval = pvconn_accept(pvconn, &new_vconn); + if (!retval && new_vconn) { + rconn = + rconn_create(60, 0, DSCP_DEFAULT, get_allowed_ofp_versions()); + rconn_connect_unreliably(rconn, new_vconn, NULL); + send_hello_packet(rconn); + } + } + if (rconn) { + rconn_run(rconn); + if (!rconn_is_connected(rconn)) { + return; + } + + while ((msg = rconn_recv(rconn)) != NULL) { + process_packet(ctx, msg); + ofpbuf_delete(msg); + } + } +} + +void +ofcontroller_wait(void) +{ + if (rconn) { + rconn_run_wait(rconn); + rconn_recv_wait(rconn); + } + pvconn_wait(pvconn); +} diff --git a/ovn/controller/ofcontroller.h b/ovn/controller/ofcontroller.h new file mode 100644 index 0000000..ea2d7de --- /dev/null +++ b/ovn/controller/ofcontroller.h @@ -0,0 +1,33 @@ + +/* 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. + */ + +#ifndef OFCONTROLLER_H +#define OFCONTROLLER_H 1 + +#include + +/* Interface for OVN main loop. */ +void ofcontroller_init(char const *); +void ofcontroller_run(struct controller_ctx *, + const struct ovsrec_bridge *br_int); +void ofcontroller_wait(void); +void ofcontroller_destroy(void); + +/* + * Get the Openflow protocol supported by the client + */ +enum ofputil_protocol ofcontroller_ofp_proto(void); +#endif /* netdev.h */ diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index 343de28..793648f 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -42,6 +42,7 @@ #include "util.h" #include "ofctrl.h" +#include "ofcontroller.h" #include "binding.h" #include "chassis.h" #include "encaps.h" @@ -274,6 +275,7 @@ main(int argc, char *argv[]) sbrec_init(); ofctrl_init(); + ofcontroller_init(get_switch_controller_path()); lflow_init(); /* Connect to OVS OVSDB instance. We do not monitor all tables by @@ -337,6 +339,7 @@ main(int argc, char *argv[]) /* Map bridges to local nets from ovn-bridge-mappings */ if (br_int) { patch_run(&ctx, br_int); + ofcontroller_run(&ctx, br_int); } if (chassis_id) { @@ -370,6 +373,7 @@ main(int argc, char *argv[]) if (br_int) { ofctrl_wait(); + ofcontroller_wait(); } poll_block(); if (should_service_stop()) {