summaryrefslogtreecommitdiffstats
path: root/docs/testing/user/userguide/06-result-store-InfluxDB.rst
blob: 7479278899fcae623b285d48cd52003279df7038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
.. This work is licensed under a Creative Commons Attribution 4.0 International
.. License.
.. http://creativecommons.org/licenses/by/4.0
.. (c) OPNFV, 2016 Huawei Technologies Co.,Ltd and others.

==============================================
Store Other Project's Test Results in InfluxDB
==============================================

Abstract
========

.. _Framework: https://wiki.opnfv.org/download/attachments/6827660/wiki.png?version=1&modificationDate=1470298075000&api=v2

This chapter illustrates how to run plug-in test cases and store test results
into community's InfluxDB. The framework is shown in Framework_.


.. image:: images/InfluxDB_store.png
   :width: 800px
   :alt: Store Other Project's Test Results in InfluxDB

Store Storperf Test Results into Community's InfluxDB
=====================================================

.. _Influxdb: https://git.opnfv.org/cgit/yardstick/tree/yardstick/dispatcher/influxdb.py
.. _Mingjiang: limingjiang@huawei.com
.. _Visual: https://wiki.opnfv.org/download/attachments/6827660/tc074.PNG?version=1&modificationDate=1470298075000&api=v2
.. _Login: http://testresults.opnfv.org/grafana/login

As shown in Framework_, there are two ways to store Storperf test results
into community's InfluxDB:

1. Yardstick executes Storperf test case (TC074), posting test job to Storperf
   container via ReST API. After the test job is completed, Yardstick reads
   test results via ReST API from Storperf and posts test data to the influxDB.

2. Additionally, Storperf can run tests by itself and post the test result
   directly to the InfluxDB. The method for posting data directly to influxDB
   will be supported in the future.

Our plan is to support rest-api in D release so that other testing projects can
call the rest-api to use yardstick dispatcher service to push data to yardstick's
influxdb database.

For now, influxdb only support line protocol, and the json protocol is deprecated.

Take ping test case for example, the raw_result is json format like this:
::

    "benchmark": {
        "timestamp": 1470315409.868095,
        "errors": "",
        "data": {
          "rtt": {
          "ares": 1.125
          }
        },
      "sequence": 1
      },
    "runner_id": 2625
  }

With the help of "influxdb_line_protocol", the json is transform to like below as a line string:
::

  'ping,deploy_scenario=unknown,host=athena.demo,installer=unknown,pod_name=unknown,
    runner_id=2625,scenarios=Ping,target=ares.demo,task_id=77755f38-1f6a-4667-a7f3-
      301c99963656,version=unknown rtt.ares=1.125 1470315409868094976'

So, for data output of json format, you just need to transform json into line format and call
influxdb api to post the data into the database. All this function has been implemented in Influxdb_.
If you need support on this, please contact Mingjiang_.
::

  curl -i -XPOST 'http://104.197.68.199:8086/write?db=yardstick' --
    data-binary 'ping,deploy_scenario=unknown,host=athena.demo,installer=unknown, ...'

Grafana will be used for visualizing the collected test data, which is shown in Visual_. Grafana
can be accessed by Login_.


.. image:: images/results_visualization.png
   :width: 800px
   :alt: results visualization
or: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * USB CDC EEM network interface driver
 * Copyright (C) 2009 Oberthur Technologies
 * by Omar Laazimani, Olivier Condemine
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ctype.h>
#include <linux/ethtool.h>
#include <linux/workqueue.h>
#include <linux/mii.h>
#include <linux/usb.h>
#include <linux/crc32.h>
#include <linux/usb/cdc.h>
#include <linux/usb/usbnet.h>
#include <linux/gfp.h>
#include <linux/if_vlan.h>


/*
 * This driver is an implementation of the CDC "Ethernet Emulation
 * Model" (EEM) specification, which encapsulates Ethernet frames
 * for transport over USB using a simpler USB device model than the
 * previous CDC "Ethernet Control Model" (ECM, or "CDC Ethernet").
 *
 * For details, see www.usb.org/developers/devclass_docs/CDC_EEM10.pdf
 *
 * This version has been tested with GIGAntIC WuaoW SIM Smart Card on 2.6.24,
 * 2.6.27 and 2.6.30rc2 kernel.
 * It has also been validated on Openmoko Om 2008.12 (based on 2.6.24 kernel).
 * build on 23-April-2009
 */

#define EEM_HEAD	2		/* 2 byte header */

/*-------------------------------------------------------------------------*/

static void eem_linkcmd_complete(struct urb *urb)
{
	dev_kfree_skb(urb->context);
	usb_free_urb(urb);
}

static void eem_linkcmd(struct usbnet *dev, struct sk_buff *skb)
{
	struct urb		*urb;
	int			status;

	urb = usb_alloc_urb(0, GFP_ATOMIC);
	if (!urb)
		goto fail;

	usb_fill_bulk_urb(urb, dev->udev, dev->out,
			skb->data, skb->len, eem_linkcmd_complete, skb);

	status = usb_submit_urb(urb, GFP_ATOMIC);
	if (status) {
		usb_free_urb(urb);
fail:
		dev_kfree_skb(skb);
		netdev_warn(dev->net, "link cmd failure\n");
		return;
	}
}

static int eem_bind(struct usbnet *dev, struct usb_interface *intf)
{
	int status = 0;

	status = usbnet_get_endpoints(dev, intf);
	if (status < 0) {
		usb_set_intfdata(intf, NULL);
		usb_driver_release_interface(driver_of(intf), intf);
		return status;
	}

	/* no jumbogram (16K) support for now */

	dev->net->hard_header_len += EEM_HEAD + ETH_FCS_LEN + VLAN_HLEN;
	dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;

	return 0;
}

/*
 * EEM permits packing multiple Ethernet frames into USB transfers
 * (a "bundle"), but for TX we don't try to do that.
 */
static struct sk_buff *eem_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
				       gfp_t flags)
{
	struct sk_buff	*skb2 = NULL;
	u16		len = skb->len;
	u32		crc = 0;
	int		padlen = 0;

	/* When ((len + EEM_HEAD + ETH_FCS_LEN) % dev->maxpacket) is
	 * zero, stick two bytes of zero length EEM packet on the end.
	 * Else the framework would add invalid single byte padding,
	 * since it can't know whether ZLPs will be handled right by
	 * all the relevant hardware and software.
	 */
	if (!((len + EEM_HEAD + ETH_FCS_LEN) % dev->maxpacket))
		padlen += 2;

	if (!skb_cloned(skb)) {
		int	headroom = skb_headroom(skb);
		int	tailroom = skb_tailroom(skb);

		if ((tailroom >= ETH_FCS_LEN + padlen) &&
		    (headroom >= EEM_HEAD))
			goto done;

		if ((headroom + tailroom)
				> (EEM_HEAD + ETH_FCS_LEN + padlen)) {
			skb->data = memmove(skb->head +
					EEM_HEAD,
					skb->data,
					skb->len);
			skb_set_tail_pointer(skb, len);
			goto done;
		}
	}

	skb2 = skb_copy_expand(skb, EEM_HEAD, ETH_FCS_LEN + padlen, flags);
	if (!skb2)
		return NULL;

	dev_kfree_skb_any(skb);
	skb = skb2;

done:
	/* we don't use the "no Ethernet CRC" option */
	crc = crc32_le(~0, skb->data, skb->len);
	crc = ~crc;

	put_unaligned_le32(crc, skb_put(skb, 4));

	/* EEM packet header format:
	 * b0..13:	length of ethernet frame
	 * b14:		bmCRC (1 == valid Ethernet CRC)
	 * b15:		bmType (0 == data)
	 */
	len = skb->len;
	put_unaligned_le16(BIT(14) | len, skb_push(skb, 2));

	/* Bundle a zero length EEM packet if needed */
	if (padlen)
		put_unaligned_le16(0, skb_put(skb, 2));

	return skb;
}

static int eem_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
{
	/*
	 * Our task here is to strip off framing, leaving skb with one
	 * data frame for the usbnet framework code to process.  But we
	 * may have received multiple EEM payloads, or command payloads.
	 * So we must process _everything_ as if it's a header, except
	 * maybe the last data payload
	 *
	 * REVISIT the framework needs updating so that when we consume
	 * all payloads (the last or only message was a command, or a
	 * zero length EEM packet) that is not accounted as an rx_error.
	 */
	do {
		struct sk_buff	*skb2 = NULL;
		u16		header;
		u16		len = 0;

		/* incomplete EEM header? */
		if (skb->len < EEM_HEAD)
			return 0;

		/*
		 * EEM packet header format:
		 * b0..14:	EEM type dependent (Data or Command)
		 * b15:		bmType
		 */
		header = get_unaligned_le16(skb->data);
		skb_pull(skb, EEM_HEAD);

		/*
		 * The bmType bit helps to denote when EEM
		 * packet is data or command :
		 *	bmType = 0	: EEM data payload
		 *	bmType = 1	: EEM (link) command
		 */
		if (header & BIT(15)) {
			u16	bmEEMCmd;

			/*
			 * EEM (link) command packet:
			 * b0..10:	bmEEMCmdParam
			 * b11..13:	bmEEMCmd
			 * b14:		bmReserved (must be 0)
			 * b15:		1 (EEM command)
			 */
			if (header & BIT(14)) {
				netdev_dbg(dev->net, "reserved command %04x\n",
					   header);
				continue;
			}

			bmEEMCmd = (header >> 11) & 0x7;
			switch (bmEEMCmd) {

			/* Responding to echo requests is mandatory. */
			case 0:		/* Echo command */
				len = header & 0x7FF;

				/* bogus command? */
				if (skb->len < len)
					return 0;

				skb2 = skb_clone(skb, GFP_ATOMIC);
				if (unlikely(!skb2))
					goto next;
				skb_trim(skb2, len);
				put_unaligned_le16(BIT(15) | (1 << 11) | len,
						skb_push(skb2, 2));
				eem_linkcmd(dev, skb2);
				break;

			/*
			 * Host may choose to ignore hints.
			 *  - suspend: peripheral ready to suspend
			 *  - response: suggest N millisec polling
			 *  - response complete: suggest N sec polling
			 *
			 * Suspend is reported and maybe heeded.
			 */
			case 2:		/* Suspend hint */
				usbnet_device_suggests_idle(dev);
				continue;
			case 3:		/* Response hint */
			case 4:		/* Response complete hint */
				continue;

			/*
			 * Hosts should never receive host-to-peripheral
			 * or reserved command codes; or responses to an
			 * echo command we didn't send.
			 */
			case 1:		/* Echo response */
			case 5:		/* Tickle */
			default:	/* reserved */
				netdev_warn(dev->net,
					    "unexpected link command %d\n",
					    bmEEMCmd);
				continue;
			}

		} else {
			u32	crc, crc2;
			int	is_last;

			/* zero length EEM packet? */
			if (header == 0)
				continue;

			/*
			 * EEM data packet header :
			 * b0..13:	length of ethernet frame
			 * b14:		bmCRC
			 * b15:		0 (EEM data)
			 */
			len = header & 0x3FFF;

			/* bogus EEM payload? */
			if (skb->len < len)
				return 0;

			/* bogus ethernet frame? */
			if (len < (ETH_HLEN + ETH_FCS_LEN))
				goto next;

			/*
			 * Treat the last payload differently: framework
			 * code expects our "fixup" to have stripped off
			 * headers, so "skb" is a data packet (or error).
			 * Else if it's not the last payload, keep "skb"
			 * for further processing.
			 */
			is_last = (len == skb->len);
			if (is_last)
				skb2 = skb;
			else {
				skb2 = skb_clone(skb, GFP_ATOMIC);
				if (unlikely(!skb2))
					return 0;
			}

			/*
			 * The bmCRC helps to denote when the CRC field in
			 * the Ethernet frame contains a calculated CRC:
			 *	bmCRC = 1	: CRC is calculated
			 *	bmCRC = 0	: CRC = 0xDEADBEEF
			 */
			if (header & BIT(14)) {
				crc = get_unaligned_le32(skb2->data
						+ len - ETH_FCS_LEN);
				crc2 = ~crc32_le(~0, skb2->data, skb2->len
						- ETH_FCS_LEN);
			} else {
				crc = get_unaligned_be32(skb2->data
						+ len - ETH_FCS_LEN);
				crc2 = 0xdeadbeef;
			}
			skb_trim(skb2, len - ETH_FCS_LEN);

			if (is_last)
				return crc == crc2;

			if (unlikely(crc != crc2)) {
				dev->net->stats.rx_errors++;
				dev_kfree_skb_any(skb2);
			} else
				usbnet_skb_return(dev, skb2);
		}

next:
		skb_pull(skb, len);
	} while (skb->len);

	return 1;
}

static const struct driver_info eem_info = {
	.description =	"CDC EEM Device",
	.flags =	FLAG_ETHER | FLAG_POINTTOPOINT,
	.bind =		eem_bind,
	.rx_fixup =	eem_rx_fixup,
	.tx_fixup =	eem_tx_fixup,
};

/*-------------------------------------------------------------------------*/

static const struct usb_device_id products[] = {
{
	USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_EEM,
			USB_CDC_PROTO_EEM),
	.driver_info = (unsigned long) &eem_info,
},
{
	/* EMPTY == end of list */
},
};
MODULE_DEVICE_TABLE(usb, products);

static struct usb_driver eem_driver = {
	.name =		"cdc_eem",
	.id_table =	products,
	.probe =	usbnet_probe,
	.disconnect =	usbnet_disconnect,
	.suspend =	usbnet_suspend,
	.resume =	usbnet_resume,
	.disable_hub_initiated_lpm = 1,
};

module_usb_driver(eem_driver);

MODULE_AUTHOR("Omar Laazimani <omar.oberthur@gmail.com>");
MODULE_DESCRIPTION("USB CDC EEM");
MODULE_LICENSE("GPL");