From patchwork Thu Aug 21 12:30:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robbie King X-Patchwork-Id: 35762 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A5FF62055D for ; Thu, 21 Aug 2014 12:31:47 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wp18sf55291593obc.5 for ; Thu, 21 Aug 2014 05:31:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=fLjn4AgZY5ZJutOV4qTx5aK1czNWZe6VLNvHhVRnHrI=; b=h/kZLPOxvj7OwQDBWmj0qukD4mcIXHAapQhPv0cdu2eGZ5TV9QFrV28zl6KNistaTT Km28RxEivp6VXFIE8RINNMQ5yJHZZVrgpDCEFx/zNf1pNFWxJpLT1R9WV7pU3xUxGFzi OkV5mfkIceRqWmx/H92pOQun0m1Z1x1tMYVaH1DRPdus6Xu6uVY7EA4vb0g1WCTRXdxF XyRCVlljyLjiOHkmx3t+SWbdSWW30E5jdNXEqSrOlfBwaqamZDYB7gLtByiIEpgjz3xd JIZFeeEfYKbYAshMp/D7Uux3S0UUMcL3m3l8WnVaoCIRG9TJ946t3lMHTkKkk/Rv2NRg BtZw== X-Gm-Message-State: ALoCoQk3MZCulxt06H64Y6fw62ayFSuK0MBfAJiwQZ34hGc2pK7CTuJeAelpUDyxXtfexDWQFK6M X-Received: by 10.182.66.234 with SMTP id i10mr29536548obt.12.1408624307236; Thu, 21 Aug 2014 05:31:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.231 with SMTP id v94ls657050qgd.14.gmail; Thu, 21 Aug 2014 05:31:47 -0700 (PDT) X-Received: by 10.53.0.164 with SMTP id az4mr48129vdd.52.1408624307119; Thu, 21 Aug 2014 05:31:47 -0700 (PDT) Received: from mail-vc0-x233.google.com (mail-vc0-x233.google.com [2607:f8b0:400c:c03::233]) by mx.google.com with ESMTPS id n8si2261059vcz.56.2014.08.21.05.31.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Aug 2014 05:31:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::233 as permitted sender) client-ip=2607:f8b0:400c:c03::233; Received: by mail-vc0-f179.google.com with SMTP id hq11so10454739vcb.24 for ; Thu, 21 Aug 2014 05:31:47 -0700 (PDT) X-Received: by 10.220.182.73 with SMTP id cb9mr42189426vcb.9.1408624307044; Thu, 21 Aug 2014 05:31:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp131543vcb; Thu, 21 Aug 2014 05:31:46 -0700 (PDT) X-Received: by 10.224.11.212 with SMTP id u20mr87349852qau.82.1408624306613; Thu, 21 Aug 2014 05:31:46 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id a34si38390792qge.110.2014.08.21.05.31.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 21 Aug 2014 05:31:46 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKRWr-0004gD-8P; Thu, 21 Aug 2014 12:31:45 +0000 Received: from rcdn-iport-3.cisco.com ([173.37.86.74]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKRVu-0004Yd-WA for lng-odp@lists.linaro.org; Thu, 21 Aug 2014 12:30:47 +0000 X-IronPort-AV: E=Sophos;i="5.01,909,1400025600"; d="scan'208";a="349237377" Received: from rcdn-core-9.cisco.com ([173.37.93.145]) by rcdn-iport-3.cisco.com with ESMTP; 21 Aug 2014 12:30:41 +0000 Received: from cpp-rtpbld-55.cisco.com (cpp-rtpbld-55.cisco.com [172.18.5.199]) by rcdn-core-9.cisco.com (8.14.5/8.14.5) with ESMTP id s7LCUfpr028076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 21 Aug 2014 12:30:41 GMT Received: from cpp-rtpbld-55.cisco.com (localhost.localdomain [127.0.0.1]) by cpp-rtpbld-55.cisco.com (8.13.8/8.13.8) with ESMTP id s7LCUfX7012532; Thu, 21 Aug 2014 08:30:41 -0400 Received: (from robking@localhost) by cpp-rtpbld-55.cisco.com (8.13.8/8.13.8/Submit) id s7LCUfSW012531; Thu, 21 Aug 2014 08:30:41 -0400 From: Robbie King To: lng-odp@lists.linaro.org Date: Thu, 21 Aug 2014 08:30:36 -0400 Message-Id: <1408624238-12430-12-git-send-email-robking@cisco.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1408624238-12430-1-git-send-email-robking@cisco.com> References: <1408624238-12430-1-git-send-email-robking@cisco.com> X-Topics: patch Subject: [lng-odp] [PATCH 11/13] IPsec example loopback interface DB X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Original-Sender: robking@cisco.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::233 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=fail header.i=@cisco.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Robbie King --- example/ipsec/odp_ipsec_loop_db.c | 54 ++++++++++++++++ example/ipsec/odp_ipsec_loop_db.h | 128 +++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 0 deletions(-) create mode 100644 example/ipsec/odp_ipsec_loop_db.c create mode 100644 example/ipsec/odp_ipsec_loop_db.h diff --git a/example/ipsec/odp_ipsec_loop_db.c b/example/ipsec/odp_ipsec_loop_db.c new file mode 100644 index 0000000..440aa07 --- /dev/null +++ b/example/ipsec/odp_ipsec_loop_db.c @@ -0,0 +1,54 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +#include +#include +#include + +#include + +loopback_db_t *loopback_db; + +void init_loopback_db(void) +{ + int idx; + + loopback_db = odp_shm_reserve("loopback_db", + sizeof(loopback_db_t), + ODP_CACHE_LINE_SIZE); + if (loopback_db == NULL) { + ODP_ERR("Error: shared mem alloc failed.\n"); + exit(EXIT_FAILURE); + } + memset(loopback_db, 0, sizeof(*loopback_db)); + + for (idx = 0; idx < MAX_LOOPBACK; idx++) { + loopback_db->intf[idx].inq_def = ODP_QUEUE_INVALID; + loopback_db->intf[idx].outq_def = ODP_QUEUE_INVALID; + } +} + +void create_loopback_db_entry(int idx, + odp_queue_t inq_def, + odp_queue_t outq_def, + odp_buffer_pool_t pkt_pool) +{ + loopback_db_entry_t *entry = &loopback_db->intf[idx]; + + /* Save queues */ + entry->inq_def = inq_def; + entry->outq_def = outq_def; + entry->pkt_pool = pkt_pool; + + /* Create dummy MAC address */ + memset(entry->mac, (0xF0 | idx), sizeof(entry->mac)); +} + + + diff --git a/example/ipsec/odp_ipsec_loop_db.h b/example/ipsec/odp_ipsec_loop_db.h new file mode 100644 index 0000000..3b6c864 --- /dev/null +++ b/example/ipsec/odp_ipsec_loop_db.h @@ -0,0 +1,128 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_IPSEC_LOOP_DB_H_ +#define ODP_IPSEC_LOOP_DB_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** + * Loopback database entry structure + */ +typedef struct loopback_db_entry_s { + odp_queue_t inq_def; + odp_queue_t outq_def; + odp_buffer_pool_t pkt_pool; + uint8_t mac[6]; +} loopback_db_entry_t; + +typedef struct loopback_db_s { + loopback_db_entry_t intf[MAX_LOOPBACK]; +} loopback_db_t; + +extern loopback_db_t *loopback_db; + +/** Initialize loopback database global control structure */ +void init_loopback_db(void); + +/** + * Create loopback DB entry for an interface + * + * Loopback interfaces are specified from command line with + * an index 0-9. + * + * @param idx Index of interface in database + * @param inq_def Input queue + * @param outq_def Output queue + * @param pkt_pool Pool to create packets from + */ +void create_loopback_db_entry(int idx, + odp_queue_t inq_def, + odp_queue_t outq_def, + odp_buffer_pool_t pkt_pool); + +/** + * Parse loop interface index + * + * @param b Pointer to buffer to parse + * + * @return interface index (0 to (MAX_LOOPBACK - 1)) else -1 + */ +static inline +int loop_if_index(char *b) +{ + int ret; + int idx; + + /* Derive loopback interface index */ + ret = sscanf(b, "loop%d", &idx); + if ((1 != ret) || (idx < 0) || (idx >= MAX_LOOPBACK)) + return -1; + return idx; +} + +/** + * Query loopback DB entry MAC address + * + * @param idx Loopback DB index of the interface + * + * @return MAC address pointer + */ +static inline +uint8_t *query_loopback_db_mac(int idx) +{ + return loopback_db->intf[idx].mac; +} + +/** + * Query loopback DB entry input queue + * + * @param idx Loopback DB index of the interface + * + * @return ODP queue + */ +static inline +odp_queue_t query_loopback_db_inq(int idx) +{ + return loopback_db->intf[idx].inq_def; +} + +/** + * Query loopback DB entry output queue + * + * @param idx Loopback DB index of the interface + * + * @return ODP queue + */ +static inline +odp_queue_t query_loopback_db_outq(int idx) +{ + return loopback_db->intf[idx].outq_def; +} + +/** + * Query loopback DB entry packet pool + * + * @param idx Loopback DB index of the interface + * + * @return ODP buffer pool + */ +static inline +odp_buffer_pool_t query_loopback_db_pkt_pool(int idx) +{ + return loopback_db->intf[idx].pkt_pool; +} + +#ifdef __cplusplus +} +#endif + +#endif