📄 rsvp_specs.c
字号:
/* * @(#) $Id: rsvp_specs.c,v 1.1.1.1 2000/05/08 22:51:24 wenqing Exp $ *//************************ rsvp_specs.c *************************** * * * Routines that know service-dependent formats -- flowspecs, * * Adspecs, and Tspecs. These routines merge, convert byte * * order, and format these objects. * * * *****************************************************************//*****************************************************************************//* *//* RSVPD -- ReSerVation Protocol Daemon *//* *//* USC Information Sciences Institute *//* Marina del Rey, California *//* *//* Original Version: Shai Herzog, Nov. 1993. *//* Current Version: Steven Berson & Bob Braden, May 1996. *//* *//* Copyright (c) 1996 by the University of Southern California *//* All rights reserved. *//* *//* Permission to use, copy, modify, and distribute this software and *//* its documentation in source and binary forms for any purpose and *//* without fee is hereby granted, provided that both the above *//* copyright notice and this permission notice appear in all copies, *//* and that any documentation, advertising materials, and other *//* materials related to such distribution and use acknowledge that *//* the software was developed in part by the University of Southern *//* California, Information Sciences Institute. The name of the *//* University may not be used to endorse or promote products derived *//* from this software without specific prior written permission. *//* *//* *//* THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about *//* the suitability of this software for any purpose. 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. *//* *//*****************************************************************************/#include <stdio.h>#include <sys/param.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <string.h>#include <assert.h>#include <math.h>#include "config.h"#ifdef STANDARD_C_LIBRARY# include <stdlib.h># include <stddef.h> /* for offsetof */#else# include <malloc.h># include <memory.h>#endif#include "rsvp_socks.h"#include "rsvp.h"#include "rsvp_mac.h"#include "rsvp_specs.h"#include "rsvp_api.h"#include "rapi_lib.h"#ifdef RSVP_TCPDUMP#define _MACHINE_ENDIAN_H_ 1#endifchar *fmt_flowspec1();#ifdef RSVP_TCPDUMPextern char *getname();#else#endif/* Endian conversions for Integrated Services headers * */#define NTOH_IS_Main_Hdr(p) NTOH16((p)->ismh_len32b)#define NTOH_IS_Serv_Hdr(p) NTOH16((p)->issh_len32b)#define NTOH_IS_Parm_Hdr(p) NTOH16((p)->isph_len32b)#define HTON_IS_Main_Hdr(p) HTON16((p)->ismh_len32b)#define HTON_IS_Parm_Hdr(p) HTON16((p)->isph_len32b)#define HTON_IS_Serv_Hdr(p) HTON16((p)->issh_len32b)/* * External declarations */char * rapi_fmt_specbody3(IS_specbody_t *);char * rapi_fmt_tspecbody3(IS_tspbody_t *);char * rapi_fmt_adspecbody3(IS_adsbody_t *);/* * Forward declarations */int Compare_Flowspecs(FLOWSPEC *, FLOWSPEC *);FLOWSPEC *LUB_of_Flowspecs(FLOWSPEC *, FLOWSPEC *);FLOWSPEC *GLB_of_Flowspecs(FLOWSPEC *, FLOWSPEC *);int Compare_Tspecs(SENDER_TSPEC *, SENDER_TSPEC *);int addTspec2sum(SENDER_TSPEC *, SENDER_TSPEC *);int newTspec_sum(SENDER_TSPEC *, SENDER_TSPEC *);int Compare_Adspecs(ADSPEC *, ADSPEC *);int New_Adspec(ADSPEC *);char * fmt_flowspec(FLOWSPEC *);char * fmt_tspec(SENDER_TSPEC *);char * fmt_adspec(ADSPEC *);void hton_flowspec(FLOWSPEC *);void ntoh_flowspec(FLOWSPEC *);void hton_tspec(SENDER_TSPEC *);void ntoh_tspec(SENDER_TSPEC *);void hton_adspec(ADSPEC *);void ntoh_adspec(ADSPEC *);void hton_genparm(IS_parm_hdr_t *);void ntoh_genparm(IS_parm_hdr_t *);/* * Compare_Flowspec(): Compare two flowspecs and return one of: * SPEC1_GTR: First is bigger * SPECS_EQL: Two are equal (identical) * SPEC2_GTR: Second is bigger * SPECS_USELUB: An LUB different from both can be computed * SPECS_INCOMPAT: They are incompatible. * SPEC1_BAD: First contains error * SPEC2_BAD: Second contains error * */intCompare_Flowspecs(FLOWSPEC *s1, FLOWSPEC *s2) { IS_serv_hdr_t *sp1, *sp2; if (s1 == NULL) { if (s2 == NULL) return SPECS_EQL; else return SPEC1_LSS; } if (s2 == NULL) return SPEC1_GTR; if (Obj_CType(s1) != ctype_FLOWSPEC_Intserv0) return SPEC1_BAD; if (Obj_CType(s2) != ctype_FLOWSPEC_Intserv0) return SPEC2_BAD; sp1 = (IS_serv_hdr_t *) &s1->flow_body.spec_u; sp2 = (IS_serv_hdr_t *) &s2->flow_body.spec_u; /* For now, regard two different services as incompatible. */ if (sp1->issh_service != sp2->issh_service) return SPECS_INCOMPAT; switch (sp1->issh_service) { case GUARANTEED_SERV: { Guar_flowspec_t *o1 = (Guar_flowspec_t *) sp1; Guar_flowspec_t *o2 = (Guar_flowspec_t *) sp2; if (o1->Gspec_r == o2->Gspec_r && o1->Gspec_b == o2->Gspec_b && o1->Gspec_p == o2->Gspec_p && o1->Gspec_m == o2->Gspec_m && o1->Gspec_M == o2->Gspec_M && o1->Gspec_R == o2->Gspec_R && o1->Gspec_S == o2->Gspec_S) return SPECS_EQL; if (o1->Gspec_r >= o2->Gspec_r && o1->Gspec_b >= o2->Gspec_b && o1->Gspec_p >= o2->Gspec_p && o1->Gspec_m <= o2->Gspec_m && o1->Gspec_M >= o2->Gspec_M && o1->Gspec_R >= o2->Gspec_R && o1->Gspec_S <= o2->Gspec_S) return SPEC1_GTR; if (o1->Gspec_r <= o2->Gspec_r && o1->Gspec_b <= o2->Gspec_b && o1->Gspec_p <= o2->Gspec_p && o1->Gspec_m >= o2->Gspec_m && o1->Gspec_M <= o2->Gspec_M && o1->Gspec_R <= o2->Gspec_R && o1->Gspec_S >= o2->Gspec_S) return SPEC1_LSS; return SPECS_USELUB; } case CONTROLLED_LOAD_SERV: { CL_flowspec_t *o1 = (CL_flowspec_t *) sp1; CL_flowspec_t *o2 = (CL_flowspec_t *) sp2; if (o1->CLspec_r == o2->CLspec_r && o1->CLspec_b == o2->CLspec_b && o1->CLspec_m == o2->CLspec_m && o1->CLspec_M == o2->CLspec_M) return SPECS_EQL; if (o1->CLspec_r >= o2->CLspec_r && o1->CLspec_b >= o2->CLspec_b && o1->CLspec_m <= o2->CLspec_m && o1->CLspec_M >= o2->CLspec_M) return SPEC1_GTR; if (o1->CLspec_r <= o2->CLspec_r && o1->CLspec_b <= o2->CLspec_b && o1->CLspec_m >= o2->CLspec_m && o1->CLspec_M <= o2->CLspec_M) return SPEC1_LSS; return SPECS_USELUB; } default: break; } return SPECS_INCOMPAT;}/* * Merge two flowspecs by computing their LUB. * * Be warned that LUB_of_Flowspecs() uses a static buffer to return * flowspecs, make sure to copy ... */FLOWSPEC *LUB_of_Flowspecs(FLOWSPEC *s1, FLOWSPEC *s2) { IS_serv_hdr_t *sp1, *sp2; static FLOWSPEC sx; float32_t INFINITY32f = HUGE_VAL; if (s1 == NULL) return(s2); else if (s2 == NULL) return(s1); if (Obj_CType(s1) != ctype_FLOWSPEC_Intserv0) return NULL; if (Intserv_Obj_size(&s1->flow_body.spec_mh) != Obj_Length(s1) || !Intserv_Version_OK(&s1->flow_body.spec_mh)) return NULL; sp1 = (IS_serv_hdr_t *) &s1->flow_body.spec_u; sp2 = (IS_serv_hdr_t *) &s2->flow_body.spec_u; if (sp1->issh_service != sp2->issh_service) return(NULL); sx.flow_body.spec_mh.ismh_version = INTSERV_VERSION0; switch (sp1->issh_service) { case GUARANTEED_SERV: { Guar_flowspec_t *gp1 = (Guar_flowspec_t *) sp1; Guar_flowspec_t *gp2 = (Guar_flowspec_t *) sp2; Guar_flowspec_t *gpx = (Guar_flowspec_t *) &sx.flow_body.spec_u; Init_Var_Obj(&sx,FLOWSPEC,FLOWSPEC_Intserv0, sizeof(Guar_flowspec_t) + sizeof(IS_main_hdr_t) + sizeof(Object_header)); Set_Main_Hdr(&sx.flow_body.spec_mh, sizeof(Guar_flowspec_t)); Set_Serv_Hdr(&gpx->Guar_serv_hdr, GUARANTEED_SERV, Gspec_len); Set_Parm_Hdr(&gpx->Guar_Tspec_hdr, IS_WKP_TB_TSPEC, sizeof(TB_Tsp_parms_t)); gpx->Gspec_r = MAX(gp1->Gspec_r, gp2->Gspec_r); gpx->Gspec_b = MAX(gp1->Gspec_b, gp2->Gspec_b); gpx->Gspec_p = MAX(gp1->Gspec_p, gp2->Gspec_p); gpx->Gspec_m = MIN(gp1->Gspec_m, gp2->Gspec_m); gpx->Gspec_M = MAX(gp1->Gspec_M, gp2->Gspec_M); Set_Parm_Hdr(&gpx->Guar_Rspec_hdr, IS_GUAR_RSPEC, sizeof(guar_Rspec_t)); gpx->Gspec_R = MAX(gp1->Gspec_R, gp2->Gspec_R); gpx->Gspec_S = MIN(gp1->Gspec_S, gp2->Gspec_S); /* * Sanity check of merged reservation can go here */ } break; case CONTROLLED_LOAD_SERV: { CL_flowspec_t *clp1 = (CL_flowspec_t *) sp1; CL_flowspec_t *clp2 = (CL_flowspec_t *) sp2; CL_flowspec_t *clpx = (CL_flowspec_t *) &sx.flow_body.spec_u.CL_spec; Init_Var_Obj(&sx,FLOWSPEC,FLOWSPEC_Intserv0, sizeof(CL_flowspec_t) + sizeof(IS_main_hdr_t) + sizeof(Object_header)); Set_Main_Hdr(&sx.flow_body.spec_mh, sizeof(CL_flowspec_t)); Set_Serv_Hdr(&clpx->CL_spec_serv_hdr, CONTROLLED_LOAD_SERV, CLspec_len); Set_Parm_Hdr(&clpx->CL_spec_parm_hdr, IS_WKP_TB_TSPEC, sizeof(TB_Tsp_parms_t)); clpx->CLspec_r = MAX(clp1->CLspec_r, clp2->CLspec_r); clpx->CLspec_b = MAX(clp1->CLspec_b, clp2->CLspec_b); clpx->CLspec_p = INFINITY32f; clpx->CLspec_m = MIN(clp1->CLspec_m, clp2->CLspec_m); clpx->CLspec_M = MAX(clp1->CLspec_M, clp2->CLspec_M); } break; default: return NULL; } return (FLOWSPEC *) &sx;}/* * Merge two flowspecs by computing their GLB. * * Be warned that GLB_of_Flowspecs() uses a static buffer to return * flowspecs, make sure to copy ... */FLOWSPEC *GLB_of_Flowspecs(FLOWSPEC *s1, FLOWSPEC *s2) { IS_serv_hdr_t *sp1, *sp2; static FLOWSPEC sx; float32_t INFINITY32f = HUGE_VAL; if (s1 == NULL) return(s2); else if (s2 == NULL) return(s1); if (Obj_CType(s1) != ctype_FLOWSPEC_Intserv0) return NULL; if (Intserv_Obj_size(&s1->flow_body.spec_mh) != Obj_Length(s1) || !Intserv_Version_OK(&s1->flow_body.spec_mh)) return NULL; sp1 = (IS_serv_hdr_t *) &s1->flow_body.spec_u; sp2 = (IS_serv_hdr_t *) &s2->flow_body.spec_u; if (sp1->issh_service != sp2->issh_service) return(NULL); switch (sp1->issh_service) { case GUARANTEED_SERV: { Guar_flowspec_t *gp1 = (Guar_flowspec_t *) sp1; Guar_flowspec_t *gp2 = (Guar_flowspec_t *) sp2; Guar_flowspec_t *gpx = (Guar_flowspec_t *) &sx.flow_body.spec_u; Init_Var_Obj(&sx,FLOWSPEC,FLOWSPEC_Intserv0, sizeof(Guar_flowspec_t) + sizeof(IS_main_hdr_t) + sizeof(Object_header)); Set_Main_Hdr(&sx.flow_body.spec_mh, sizeof(Guar_flowspec_t)); Set_Serv_Hdr(&gpx->Guar_serv_hdr, GUARANTEED_SERV, Gspec_len); Set_Parm_Hdr(&gpx->Guar_Tspec_hdr, IS_WKP_TB_TSPEC, sizeof(TB_Tsp_parms_t)); gpx->Gspec_r = MIN(gp1->Gspec_r, gp2->Gspec_r); gpx->Gspec_b = MIN(gp1->Gspec_b, gp2->Gspec_b); gpx->Gspec_p = MIN(gp1->Gspec_p, gp2->Gspec_p); gpx->Gspec_m = MAX(gp1->Gspec_m, gp2->Gspec_m); gpx->Gspec_M = MIN(gp1->Gspec_M, gp2->Gspec_M); Set_Parm_Hdr(&gpx->Guar_Rspec_hdr, IS_GUAR_RSPEC, sizeof(guar_Rspec_t)); gpx->Gspec_R = MIN(gp1->Gspec_R, gp2->Gspec_R); gpx->Gspec_S = MAX(gp1->Gspec_S, gp2->Gspec_S); /* * Sanity check of merged reservation can go here */ } break; case CONTROLLED_LOAD_SERV: { CL_flowspec_t *clp1 = (CL_flowspec_t *) sp1; CL_flowspec_t *clp2 = (CL_flowspec_t *) sp2; CL_flowspec_t *clpx = (CL_flowspec_t *) &sx.flow_body.spec_u; Init_Var_Obj(&sx,FLOWSPEC,FLOWSPEC_Intserv0, sizeof(CL_flowspec_t) + sizeof(IS_main_hdr_t) + sizeof(Object_header)); Set_Main_Hdr(&sx.flow_body.spec_mh, sizeof(CL_flowspec_t)); Set_Serv_Hdr(&clpx->CL_spec_serv_hdr, CONTROLLED_LOAD_SERV, CLspec_len); Set_Parm_Hdr(&clpx->CL_spec_parm_hdr, IS_WKP_TB_TSPEC, sizeof(TB_Tsp_parms_t));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -