Blame osmtest/include/osmtest_subnet.h

Packit 13e616
/*
Packit 13e616
 * Copyright (c) 2006 Voltaire, Inc. All rights reserved.
Packit 13e616
 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
Packit 13e616
 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
Packit 13e616
 *
Packit 13e616
 * This software is available to you under a choice of one of two
Packit 13e616
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit 13e616
 * General Public License (GPL) Version 2, available from the file
Packit 13e616
 * COPYING in the main directory of this source tree, or the
Packit 13e616
 * OpenIB.org BSD license below:
Packit 13e616
 *
Packit 13e616
 *     Redistribution and use in source and binary forms, with or
Packit 13e616
 *     without modification, are permitted provided that the following
Packit 13e616
 *     conditions are met:
Packit 13e616
 *
Packit 13e616
 *      - Redistributions of source code must retain the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer.
Packit 13e616
 *
Packit 13e616
 *      - Redistributions in binary form must reproduce the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer in the documentation and/or other materials
Packit 13e616
 *        provided with the distribution.
Packit 13e616
 *
Packit 13e616
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 13e616
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 13e616
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 13e616
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 13e616
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 13e616
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 13e616
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 13e616
 * SOFTWARE.
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Abstract:
Packit 13e616
 * 	Declaration of osmtest_t.
Packit 13e616
 *	This object represents the OSMTest Test object.
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
Packit 13e616
#ifndef _OSMTEST_SUBNET_H_
Packit 13e616
#define _OSMTEST_SUBNET_H_
Packit 13e616
Packit 13e616
#include <stdlib.h>
Packit 13e616
#include <complib/cl_qmap.h>
Packit 13e616
#include <opensm/osm_log.h>
Packit 13e616
#include <vendor/osm_vendor_api.h>
Packit 13e616
#include <opensm/osm_mad_pool.h>
Packit 13e616
#include <opensm/osm_helper.h>
Packit 13e616
Packit 13e616
/****s* Subnet Database/generic_t
Packit 13e616
* NAME
Packit 13e616
*	generic_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	Subnet database object for fields common to all record types.
Packit 13e616
*	All other database types must be castable to this type.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef struct _generic {
Packit 13e616
	cl_map_item_t map_item;	/* must be first element! */
Packit 13e616
	uint32_t count;		/* must be second element! */
Packit 13e616
} generic_t;
Packit 13e616
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****s* Subnet Database/node_t
Packit 13e616
* NAME
Packit 13e616
*	node_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	Subnet database object for nodes.
Packit 13e616
*	Must be castable to generic_t.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef struct _node {
Packit 13e616
	cl_map_item_t map_item;	/* must be first element! */
Packit 13e616
	uint32_t count;		/* must be second element! */
Packit 13e616
	ib_node_record_t rec;
Packit 13e616
	ib_node_record_t comp;
Packit 13e616
} node_t;
Packit 13e616
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
* map_item
Packit 13e616
*	Provides linkage for the qmap container.
Packit 13e616
*
Packit 13e616
* rec
Packit 13e616
*	NodeRecord for this node as read from the database file.
Packit 13e616
*
Packit 13e616
* comp
Packit 13e616
*	NodeRecord indicating which fields should be compared against rec.
Packit 13e616
*	Bits set in the comp NodeRecord indicate that bit in the rec structure
Packit 13e616
*	should be compared against real-time data from the SA.
Packit 13e616
*
Packit 13e616
* count
Packit 13e616
*	Utility counter used by the validation logic.  Typically used to
Packit 13e616
*	to indicate the number of times a matching node was received from
Packit 13e616
*	the SA.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*********/
Packit 13e616
Packit 13e616
static inline node_t *node_new(void)
Packit 13e616
{
Packit 13e616
	node_t *p_obj;
Packit 13e616
Packit 13e616
	p_obj = malloc(sizeof(*p_obj));
Packit 13e616
	if (p_obj)
Packit 13e616
		memset(p_obj, 0, sizeof(*p_obj));
Packit 13e616
	return (p_obj);
Packit 13e616
}
Packit 13e616
Packit 13e616
static inline void node_delete(IN node_t * p_obj)
Packit 13e616
{
Packit 13e616
	free(p_obj);
Packit 13e616
}
Packit 13e616
Packit 13e616
/****s* Subnet Database/port_t
Packit 13e616
* NAME
Packit 13e616
*	port_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	Subnet database object for ports.
Packit 13e616
*	Must be castable to generic_t.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef struct _port {
Packit 13e616
	cl_map_item_t map_item;	/* must be first element! */
Packit 13e616
	uint32_t count;		/* must be second element! */
Packit 13e616
	/* Since there is no unique identifier for all ports we
Packit 13e616
	   must be able to have such a key by the lid and port num */
Packit 13e616
	uint64_t port_id;
Packit 13e616
	ib_portinfo_record_t rec;
Packit 13e616
	ib_portinfo_record_t comp;
Packit 13e616
} port_t;
Packit 13e616
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
*
Packit 13e616
* map_item
Packit 13e616
*	Provides linkage for the qmap container.
Packit 13e616
*
Packit 13e616
* rec
Packit 13e616
*	PortInfoRecord for this port as read from the database file.
Packit 13e616
*
Packit 13e616
* comp
Packit 13e616
*	PortInfoRecord indicating which fields should be compared against rec.
Packit 13e616
*	Bits set in the comp NodeRecord indicate that bit in the rec structure
Packit 13e616
*	should be compared against real-time data from the SA.
Packit 13e616
*
Packit 13e616
* count
Packit 13e616
*	Utility counter used by the validation logic.  Typically used to
Packit 13e616
*	to indicate the number of times a matching node was received from
Packit 13e616
*	the SA.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*********/
Packit 13e616
Packit 13e616
static inline port_t *port_new(void)
Packit 13e616
{
Packit 13e616
	port_t *p_obj;
Packit 13e616
Packit 13e616
	p_obj = malloc(sizeof(*p_obj));
Packit 13e616
	if (p_obj)
Packit 13e616
		memset(p_obj, 0, sizeof(*p_obj));
Packit 13e616
	return (p_obj);
Packit 13e616
}
Packit 13e616
Packit 13e616
static inline void port_delete(IN port_t * p_obj)
Packit 13e616
{
Packit 13e616
	free(p_obj);
Packit 13e616
}
Packit 13e616
Packit 13e616
static inline uint64_t
Packit 13e616
port_gen_id(IN ib_net16_t const lid, IN uint8_t const port_num)
Packit 13e616
{
Packit 13e616
	return (lid << 8 | port_num);
Packit 13e616
}
Packit 13e616
Packit 13e616
static inline void
Packit 13e616
port_ext_id(IN uint64_t id, IN ib_net16_t * p_lid, IN uint8_t * p_port_num)
Packit 13e616
{
Packit 13e616
	CL_ASSERT((id & 0xFF) < 0x100);
Packit 13e616
	*p_port_num = (uint8_t) (id & 0xFF);
Packit 13e616
	CL_ASSERT(((id >> 8) & 0xFFFF) < 0x10000);
Packit 13e616
	*p_lid = (uint16_t) ((id >> 8) & 0xFFFF);
Packit 13e616
}
Packit 13e616
Packit 13e616
static inline void
Packit 13e616
port_set_id(IN port_t * p_obj,
Packit 13e616
	    IN ib_net16_t const lid, IN uint8_t const port_num)
Packit 13e616
{
Packit 13e616
	p_obj->port_id = port_gen_id(lid, port_num);
Packit 13e616
}
Packit 13e616
Packit 13e616
static inline void
Packit 13e616
port_get_id(IN port_t * p_obj, IN ib_net16_t * p_lid, IN uint8_t * p_port_num)
Packit 13e616
{
Packit 13e616
	port_ext_id(p_obj->port_id, p_lid, p_port_num);
Packit 13e616
}
Packit 13e616
Packit 13e616
/****s* Subnet Database/path_t
Packit 13e616
* NAME
Packit 13e616
*	node_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	Subnet database object for paths.
Packit 13e616
*	Must be castable to generic_t.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef struct _path {
Packit 13e616
	cl_map_item_t map_item;	/* must be first element! */
Packit 13e616
	uint32_t count;		/* must be second element! */
Packit 13e616
	ib_path_rec_t rec;
Packit 13e616
	ib_path_rec_t comp;
Packit 13e616
} path_t;
Packit 13e616
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
* map_item
Packit 13e616
*	Provides linkage for the qmap container.
Packit 13e616
*
Packit 13e616
* rec
Packit 13e616
*	PathRecord for this path as read from the database file.
Packit 13e616
*
Packit 13e616
* comp
Packit 13e616
*	PathRecord indicating which fields should be compared against rec.
Packit 13e616
*	Bits set in the comp PathRecord indicate that bit in the rec structure
Packit 13e616
*	should be compared against real-time data from the SA.
Packit 13e616
*
Packit 13e616
* count
Packit 13e616
*	Utility counter used by the validation logic.  Typically used to
Packit 13e616
*	to indicate the number of times a matching node was received from
Packit 13e616
*	the SA.
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*********/
Packit 13e616
Packit 13e616
static inline path_t *path_new(void)
Packit 13e616
{
Packit 13e616
	path_t *p_obj;
Packit 13e616
Packit 13e616
	p_obj = malloc(sizeof(*p_obj));
Packit 13e616
	if (p_obj)
Packit 13e616
		memset(p_obj, 0, sizeof(*p_obj));
Packit 13e616
	return (p_obj);
Packit 13e616
}
Packit 13e616
Packit 13e616
static inline void path_delete(IN path_t * p_obj)
Packit 13e616
{
Packit 13e616
	free(p_obj);
Packit 13e616
}
Packit 13e616
Packit 13e616
/****s* Subnet Database/subnet_t
Packit 13e616
* NAME
Packit 13e616
*	subnet_t
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	Subnet database object.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
typedef struct _subnet {
Packit 13e616
	cl_qmap_t node_lid_tbl;
Packit 13e616
	cl_qmap_t node_guid_tbl;
Packit 13e616
	cl_qmap_t mgrp_mlid_tbl;
Packit 13e616
	/* cl_qmap_t port_lid_tbl; */
Packit 13e616
	/* cl_qmap_t port_guid_tbl; */
Packit 13e616
	cl_qmap_t port_key_tbl;
Packit 13e616
	cl_qmap_t link_tbl;
Packit 13e616
	cl_qmap_t path_tbl;
Packit 13e616
} subnet_t;
Packit 13e616
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Subnet Database/subnet_construct
Packit 13e616
* NAME
Packit 13e616
*	subnet_construct
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	This function constructs an subnet database object.
Packit 13e616
*	This function cannot fail.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
void subnet_construct(IN subnet_t * const p_subn);
Packit 13e616
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*********/
Packit 13e616
Packit 13e616
/****f* Subnet Database/subnet_init
Packit 13e616
* NAME
Packit 13e616
*	subnet_init
Packit 13e616
*
Packit 13e616
* DESCRIPTION
Packit 13e616
*	This function initializes an subnet database object.
Packit 13e616
*
Packit 13e616
* SYNOPSIS
Packit 13e616
*/
Packit 13e616
cl_status_t subnet_init(IN subnet_t * const p_subn);
Packit 13e616
Packit 13e616
/*
Packit 13e616
* FIELDS
Packit 13e616
*
Packit 13e616
* SEE ALSO
Packit 13e616
*********/
Packit 13e616
Packit 13e616
#endif