Annotation of cf/hv_atmsw.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Cisco 7200 (Predator) simulation platform.
        !             3:  * Copyright (c) 2006 Christophe Fillot ([email protected])
        !             4:  *
        !             5:  * Hypervisor ATM switch routines.
        !             6:  */
        !             7: 
        !             8: #include <stdio.h>
        !             9: #include <stdlib.h>
        !            10: #include <unistd.h>
        !            11: #include <string.h>
        !            12: #include <sys/types.h>
        !            13: #include <sys/stat.h>
        !            14: #include <sys/mman.h>
        !            15: #include <signal.h>
        !            16: #include <fcntl.h>
        !            17: #include <errno.h>
        !            18: #include <assert.h>
        !            19: #include <stdarg.h>
        !            20: #include <sys/ioctl.h>
        !            21: #include <sys/types.h>
        !            22: #include <sys/socket.h>
        !            23: #include <arpa/inet.h>
        !            24: #include <pthread.h>
        !            25: 
        !            26: #include "mips64.h"
        !            27: #include "dynamips.h"
        !            28: #include "utils.h"
        !            29: #include "net.h"
        !            30: #include "atm.h"
        !            31: #include "frame_relay.h"
        !            32: #include "crc.h"
        !            33: #include "net_io.h"
        !            34: #include "registry.h"
        !            35: #include "hypervisor.h"
        !            36: 
        !            37: /* Create a new ATMSW object */
        !            38: static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])
        !            39: {
        !            40:    atmsw_table_t *t;
        !            41: 
        !            42:    if (!(t = atmsw_create_table(argv[0]))) {
        !            43:       hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
        !            44:                             "unable to create ATM switch '%s'",
        !            45:                             argv[0]);
        !            46:       return(-1);
        !            47:    }
        !            48: 
        !            49:    atmsw_release(argv[0]);
        !            50:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"ATMSW '%s' created",argv[0]);
        !            51:    return(0);
        !            52: }
        !            53: 
        !            54: /* Delete an ATM switch */
        !            55: static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
        !            56: {
        !            57:    int res;
        !            58: 
        !            59:    res = atmsw_delete(argv[0]);
        !            60: 
        !            61:    if (res == 1) {
        !            62:       hypervisor_send_reply(conn,HSC_INFO_OK,1,"ATMSW '%s' deleted",argv[0]);
        !            63:    } else {
        !            64:       hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
        !            65:                             "unable to delete ATMSW '%s'",argv[0]);
        !            66:    }
        !            67: 
        !            68:    return(res);
        !            69: }
        !            70: 
        !            71: /* 
        !            72:  * Create a Virtual Path Connection
        !            73:  *
        !            74:  * Parameters: <atmsw_name> <input_nio> <input_vpi> <output_nio> <output_vpi>
        !            75:  */
        !            76: static int cmd_create_vpc(hypervisor_conn_t *conn,int argc,char *argv[])
        !            77: {
        !            78:    atmsw_table_t *t;
        !            79: 
        !            80:    if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW)))
        !            81:       return(-1);
        !            82: 
        !            83:    /* create the connection */
        !            84:    if (atmsw_create_vpc(t,argv[1],atoi(argv[2]),argv[3],atoi(argv[4])) == -1) {
        !            85:       atmsw_release(argv[0]);
        !            86:       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to create VPC");
        !            87:       return(-1);
        !            88:    }
        !            89: 
        !            90:    atmsw_release(argv[0]);
        !            91:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"VPC created");
        !            92:    return(0);
        !            93: }
        !            94: 
        !            95: /* 
        !            96:  * Delete a Virtual Path Connection
        !            97:  *
        !            98:  * Parameters: <atmsw_name> <input_nio> <input_vpi> <output_nio> <output_vpi>
        !            99:  */
        !           100: static int cmd_delete_vpc(hypervisor_conn_t *conn,int argc,char *argv[])
        !           101: {
        !           102:    atmsw_table_t *t;
        !           103: 
        !           104:    if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW)))
        !           105:       return(-1);
        !           106: 
        !           107:    /* delete the connection */
        !           108:    if (atmsw_delete_vpc(t,argv[1],atoi(argv[2]),argv[3],atoi(argv[4])) == -1) {
        !           109:       atmsw_release(argv[0]);
        !           110:       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to delete VPC");
        !           111:       return(-1);
        !           112:    }
        !           113: 
        !           114:    atmsw_release(argv[0]);
        !           115:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"VPC deleted");
        !           116:    return(0);
        !           117: }
        !           118: 
        !           119: /* 
        !           120:  * Create a Virtual Circuit Connection
        !           121:  *
        !           122:  * Parameters: <atmsw_name> <input_nio> <input_vpi> <input_vci>
        !           123:  *             <output_nio> <output_vpi> <output_vci>
        !           124:  */
        !           125: static int cmd_create_vcc(hypervisor_conn_t *conn,int argc,char *argv[])
        !           126: {
        !           127:    atmsw_table_t *t;
        !           128: 
        !           129:    if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW)))
        !           130:       return(-1);
        !           131:    
        !           132:    /* create the connection */
        !           133:    if (atmsw_create_vcc(t,argv[1],atoi(argv[2]),atoi(argv[3]),
        !           134:                         argv[4],atoi(argv[5]),atoi(argv[6])) == -1) 
        !           135:    {
        !           136:       atmsw_release(argv[0]);
        !           137:       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to create VCC");
        !           138:       return(-1);
        !           139:    }
        !           140: 
        !           141:    atmsw_release(argv[0]);
        !           142:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"VCC created");
        !           143:    return(0);
        !           144: }
        !           145: 
        !           146: /* 
        !           147:  * Delete a Virtual Circuit Connection
        !           148:  *
        !           149:  * Parameters: <atmsw_name> <input_nio> <input_vpi> <input_vci>
        !           150:  *             <output_nio> <output_vpi> <output_vci>
        !           151:  */
        !           152: static int cmd_delete_vcc(hypervisor_conn_t *conn,int argc,char *argv[])
        !           153: {
        !           154:    atmsw_table_t *t;
        !           155: 
        !           156:    if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW)))
        !           157:       return(-1);
        !           158:    
        !           159:    /* create the connection */
        !           160:    if (atmsw_delete_vcc(t,argv[1],atoi(argv[2]),atoi(argv[3]),
        !           161:                         argv[4],atoi(argv[5]),atoi(argv[6])) == -1) 
        !           162:    {
        !           163:       atmsw_release(argv[0]);
        !           164:       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to delete VCC");
        !           165:       return(-1);
        !           166:    }
        !           167: 
        !           168:    atmsw_release(argv[0]);
        !           169:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"VCC deleted");
        !           170:    return(0);
        !           171: }
        !           172: 
        !           173: /* Show info about a ATM switch object */
        !           174: static void cmd_show_list(registry_entry_t *entry,void *opt,int *err)
        !           175: {
        !           176:    hypervisor_conn_t *conn = opt;
        !           177:    hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
        !           178: }
        !           179: 
        !           180: /* ATM switch List */
        !           181: static int cmd_list(hypervisor_conn_t *conn,int argc,char *argv[])
        !           182: {
        !           183:    int err = 0;
        !           184:    registry_foreach_type(OBJ_TYPE_ATMSW,cmd_show_list,conn,&err);
        !           185:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
        !           186:    return(0);
        !           187: }
        !           188: 
        !           189: /* ATMSW commands */
        !           190: static hypervisor_cmd_t atmsw_cmd_array[] = {
        !           191:    { "create", 1, 1, cmd_create, NULL },
        !           192:    { "delete", 1, 1, cmd_delete, NULL },
        !           193:    { "create_vpc", 5, 5, cmd_create_vpc, NULL },
        !           194:    { "delete_vpc", 5, 5, cmd_delete_vpc, NULL },
        !           195:    { "create_vcc", 7, 7, cmd_create_vcc, NULL },
        !           196:    { "delete_vcc", 7, 7, cmd_delete_vcc, NULL },
        !           197:    { "list", 0, 0, cmd_list, NULL },
        !           198:    { NULL, -1, -1, NULL, NULL },
        !           199: };
        !           200: 
        !           201: /* Hypervisor ATM switch initialization */
        !           202: int hypervisor_atmsw_init(void)
        !           203: {
        !           204:    hypervisor_module_t *module;
        !           205: 
        !           206:    module = hypervisor_register_module("atmsw");
        !           207:    assert(module != NULL);
        !           208: 
        !           209:    hypervisor_register_cmd_array(module,atmsw_cmd_array);
        !           210:    return(0);
        !           211: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.