/*
 * Copyright (c) 2000 Columbia University
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that: (1) source code distributions
 * retain the above copyright notice and this paragraph in its entirety, (2)
 * distributions including binary code include the above copyright notice and
 * this paragraph in its entirety in the documentation or other materials
 * provided with the distribution, and (3) all advertising materials mentioning
 * features or use of this software display the following acknowledgement:
 * ``This product includes software developed by Columbia University
 * and its contributors.'' Neither the name of the University nor the names 
 * of its contributors may be used to endorse or promote products derived 
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Written by Ping Pan, Columbia University, 2000
 *
 * The author would like to thank Bell Labs for providing time and freedom
 * to complete this work. Please forward bug fixes, enhancements and questions
 * to pingpan@cs.columbia.edu.
 */

/* This is a shrinked version of IntServ spec (RFC2210).
 */

#ifndef _INTSERV_H_
#define _INTSERV_H_

/* IntServ services */
#define IntServ_GenericInfo		1
#define IntServ_GuaranteedServ		2
#define IntServ_PredictiveServ		3
#define IntServ_ControlledDelay		4
#define IntServ_ControlledLoad		5

/* IntServ parameters */
#define Parameter_Num_IS_Hops		4	/* Number-of-IS-hops */
#define Parameter_Path_BW		6	/* Path-BW */
#define Parameter_Min_Path_Latency	8	/* minimum path latency */
#define Parameter_Path_MTU		10	/* path MTU */
#define Parameter_TSPEC			127	/* Token_Bucket_TSpec */
#define Parameter_GSRSPEC		130	/* Guaranteed Service RSpec */

#define Parameter_Ctot			133	/* GS */
#define Parameter_Dtot			134	/* GS */
#define Parameter_Csum			135	/* GS */
#define Parameter_Dsum			136	/* GS */


/*
 * IntServ generic header:
 * Common header and service header
 */
struct intserv_spec {
	u_int8_t	ver;		/* version */
	u_int8_t	unused;		/* not used */
	u_int16_t	len;		/* (in words) exclude the header */
	u_int8_t	serv;		/* service number */
	u_int8_t	rsv;		/* MSB is the break-bit */
	u_int16_t	serv_len;	/* service info length in words */
};

#define INTSERV_VER		0	/* current version */
#define INTSERV_VMASK		0xf0	/* version mask */
#define INTSERV_VER_OF(x)	((INTSERV_VMASK & (x->ver)) >> 4)
#define INTSERV_VALID_VER(x)				\
	(INTSERV_VER_OF(x) != INTSERV_VER ? 0 : 1)

#define INTSERV_LEN(x)			\
	((x->len * sizeof(u_int32_t)) + sizeof(u_int32_t))

/* valid service class */
#define INTSERV_VALID_SERV(x)				\
	(((x->serv) != IntServ_GuaranteedServ) &&	\
	 ((x->serv) != IntServ_ControlledLoad)) ? 0:1

/* valid service specification length */
#define INTSERV_MIN_LEN		6	/* as for control-load */
#define INTSERV_VALID_SERVLEN(x)				\
	((x->serv_len) < INTSERV_MIN_LEN) ? 0:1


/* Controlled Load Format:
 *
 *       31           24 23           16 15            8 7             0
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  1   | Ver(0)|    reserved           |   Overall Length (7)          |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  2   | Serv Num (x)  |0| reserved    |   Service Length (6)          |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  3   | Param ID (127)|    0          |  Param Lgt (5)                |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  4   |  Token Bucket Rate [r] (32-bit IEEE floating point number)    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  5   |  Token Bucket Size [b] (32-bit IEEE floating point number)    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  6   |  Peak Data Rate [p] (32-bit IEEE floating point number)       |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  7   |  Minimum Policed Unit [m] (32-bit integer)                    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  8   |  Maximum Packet Size [M]  (32-bit integer)                    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *
 * Note: this is the same as the generic Tspec in RSVP.
 * 
 */

struct intserv_clspec {
	u_int8_t	ver;		/* version */
	u_int8_t	unused;		/* not used */
	u_int16_t	len;		/* (in words) exclude the header */
	u_int8_t	serv;		/* service number */
	u_int8_t	rsvd;		/* MSB is the break-bit */
	u_int16_t	serv_len;	/* service info length in words */

	u_int8_t	tspec_id;	/* parameter id */
	u_int8_t	pads;
	u_int16_t	tspec_len;	/* length in words */
	float		token_rate;
	float		token_size;
	float		peak;
	u_int32_t	min_size;
	u_int32_t	max_size;
};


/* Guaranteed Service flowspec format:
 *
 *       31           24 23           16 15            8 7             0
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      | Ver(0)|    Unused             |     Overall Length (10)       |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      | Serv Num (2)  |0| reserved    | Service Lgt (9)               |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |Param ID (127) |    0          |  Param Lgt (5)                |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |  Token Bucket Rate [r] (32-bit IEEE floating point number)    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |  Token Bucket Size [b] (32-bit IEEE floating point number)    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |  Peak Data Rate [p] (32-bit IEEE floating point number)       |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |  Minimum Policed Unit [m] (32-bit integer)                    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |  Maximum Packet Size [M]  (32-bit integer)                    |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |Param ID (130) |    0          |  Param Lgt (2)                |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |  Requesting Rate [R] (32-bit IEEE floating point number)      |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *      |  Slack Term [S] (32-bit integer number)                       |
 *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 */

struct intserv_gsspec {
	u_int8_t	ver;		/* version */
	u_int8_t	unused;		/* not used */
	u_int16_t	len;		/* (in words) exclude the header */
	u_int8_t	serv;		/* service number */
	u_int8_t	rsvd;		/* MSB is the break-bit */
	u_int16_t	serv_len;	/* service info length in words */

	u_int8_t	tspec_id;	/* parameter id */
	u_int8_t	tspec_pad;
	u_int16_t	tspec_len;	/* length in words */
	float		token_rate;
	float		token_size;
	float		peak;
	u_int32_t	min_size;
	u_int32_t	max_size;

	u_int8_t	rspec_id;	/* parameter id */
	u_int8_t	rspec_pad;
	u_int16_t	rspec_len;	/* length in words */
	float		rate;
	u_int32_t	slack;
};

#endif
