ChoiceTable ChoiceTable::load(const std::string& fname) { std::ifstream stream(fname.c_str(),std::ios::in | std::ios::binary); if (stream) { float version; bin_read(stream,version); // version if (version != 1.0) { printf("cannot read. Wrong version nb.\n"); return ChoiceTable(0,0); } int i_size, r_size; bin_read(stream,i_size); // sizes bin_read(stream,r_size); ChoiceTable result(i_size,r_size); for (ChoiceListArray::iterator itcr = result._data.begin(); itcr != result._data.end(); ++itcr){ for (ChoiceListVector::iterator itcc = itcr->begin(); itcc != itcr->end(); ++itcc){ size_t sizerecord; // read size of a record bin_read(stream,sizerecord); itcc->resize(sizerecord); for (ChoiceList::iterator itc = itcc->begin(); itc != itcc->end(); ++itc){ // read values of a record bin_read(stream,*itc); } } } return result; } return ChoiceTable(0,0); }
int main (int argc, char *argv []) { int i ; struct node *n ; struct eq *eq ; ip_t cidr ; int c, err ; char *prog, *errstr ; prog = argv [0] ; err = 0 ; sel_init () ; while ((c = getopt (argc, argv, "an:e:E:tv:m")) != -1) { switch (c) { case 'a' : case 'n' : case 'e' : case 'E' : case 't' : case 'v' : case 'm' : if ((errstr = sel_register (c, optarg)) != NULL) { fprintf (stderr, "%s: %s\n", prog, errstr) ; err = 1 ; } break ; case '?' : default : usage (prog) ; } } if (err) exit (1) ; argc -= optind ; argv += optind ; if (argc == 0) usage (prog) ; /* * Read the graph and select subgraph */ bin_read (stdin, mobjlist) ; sel_mark () ; /* * First pass : mark all L3 nodes matching CIDR arguments */ for (i = 0 ; i < argc ; i++) { if (! ip_pton (argv [i], &cidr)) { fprintf (stderr, "%s: Invalid cidr '%s'\n", prog, argv [i]) ; exit (1) ; } for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) if (n->nodetype == NT_L3 && ip_match (&n->u.l3.addr, &cidr, 0)) MK_SET (n, MK_IPMATCH) ; } /* * Output selection arguments */ fprintf (stdout, "selection") ; for (i = 0 ; i < argc ; i++) fprintf (stdout, " %s", argv [i]) ; fprintf (stdout, "\n") ; /* * Second pass : identify all routing instances connected to those * L3 nodes we have marked before, and print equipements which are * routing instances. */ for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (n->nodetype == NT_L3 && MK_ISSET (n, MK_IPMATCH)) { struct node *r ; MK_SET (n->eq, MK_IPMATCH) ; r = get_neighbour (n, NT_ROUTER) ; if (r != NULL && ! MK_ISSET (r, MK_ISROUTER)) { MK_SET (n, MK_ISROUTER) ; MK_SET (r, MK_ISROUTER) ; MK_SET (n->eq, MK_ISROUTER) ; if (MK_ISSELECTED (n)) fprintf (stdout, "eq %s:%s router\n", n->eq->name, r->u.router.name) ; } } } /* * Third pass : print equipements which are not routing instances */ for (eq = mobj_head (eqmobj) ; eq != NULL ; eq = eq->next) if (MK_ISSET (eq, MK_IPMATCH) && ! MK_ISSET (eq, MK_ISROUTER)) if (MK_ISSELECTED (eq)) fprintf (stdout, "eq %s host\n", eq->name) ; /* * Fourth pass : identify broadcast domain for each L3 */ for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (n->nodetype == NT_L3 && MK_ISSET (n, MK_IPMATCH) && ! MK_ISSET (n, MK_PROCESSED)) walkl3 (stdout, n) ; } sel_end () ; exit (0) ; }
int main (int argc, char *argv []) { int termif, backif ; int c, err ; char *prog, *errstr ; prog = argv [0] ; err = 0 ; termif = backif = 0 ; sel_init () ; while ((c = getopt (argc, argv, "an:e:E:tv:mBb")) != -1) { switch (c) { case 'a' : case 'n' : case 'e' : case 'E' : case 't' : case 'v' : case 'm' : if ((errstr = sel_register (c, optarg)) != NULL) { fprintf (stderr, "%s: %s\n", prog, errstr) ; err = 1 ; } break ; case 'B' : termif = 1 ; break ; case 'b' : backif = 1 ; break ; case '?' : default : usage (prog) ; } } if (err) exit (1) ; argc -= optind ; argv += optind ; if (argc != 0) usage (prog) ; if (termif == 0 && backif == 0) { termif = 1 ; backif = 1 ; } /* * Read the graph and select a subgraph */ bin_read (stdin, mobjlist) ; sel_mark () ; /* * Grep interface type */ if (! termif) /* we don't want terminal interfaces */ mark_ifaces (TERMINAL) ; if (! backif) /* we don't want backbone interfaces */ mark_ifaces (! TERMINAL) ; /* * Output graph */ output_eq_ifaces (stdout) ; sel_end () ; exit (0) ; }
int main (int argc, char *argv []) { char *prog, *errstr ; int c, err ; char *eqname ; struct eq *eq, *neq ; struct node *n ; int dumpstat, dumpwifi, dumppmac, dumpipmac ; /* * Analyzes arguments */ prog = argv [0] ; err = 0 ; dumpstat = 0 ; dumpwifi = 0 ; dumppmac = 0 ; dumpipmac = 0 ; sel_init () ; while ((c = getopt (argc, argv, "an:e:E:tv:impsw")) != -1) { switch (c) { case 'a' : case 'n' : case 'e' : case 'E' : case 't' : case 'm' : case 'v' : if ((errstr = sel_register (c, optarg)) != NULL) { fprintf (stderr, "%s: %s\n", prog, errstr) ; err = 1 ; } break ; case 's' : dumpstat = 1 ; break ; case 'w' : dumpwifi = 1 ; break ; case 'p' : dumppmac = 1 ; break ; case 'i' : dumpipmac = 1 ; break ; case '?' : default : usage (prog) ; } } if (err) exit (1) ; if (dumpstat == 0 && dumpwifi == 0 && dumppmac == 0 && dumpipmac == 0) { dumpstat = 1 ; dumpwifi = 1 ; dumppmac = 1 ; dumpipmac = 1 ; } argc -= optind ; argv += optind ; switch (argc) { case 0 : eqname = NULL ; break ; case 1 : eqname = argv [0] ; break ; default : usage (prog) ; break ; } /* * Read the graph and process selection */ bin_read (stdin, mobjlist) ; for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { n->mark = 0 ; vlan_zero (n->vlanset) ; } sel_mark () ; /* * Lookup the equipment, if any */ if (eqname != NULL) { eq = eq_lookup (eqname) ; if (eq == NULL) { fprintf (stderr, "%s : equipement '%s' not found\n", prog, eqname) ; exit (1) ; } } else eq = NULL ; /* * Output the wifi probes first, since stat dump will reset marks */ if (dumpwifi) { struct ssidprobe *sp ; for (sp = mobj_head (ssidprobemobj) ; sp != NULL ; sp = sp->next) { if (eq == NULL || sp->eq == eq) if (MK_ISSELECTED (sp->l1)) output_ssidprobe (stdout, sp) ; } } if (dumppmac) { for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if ((eq == NULL || n->eq == eq) && n->nodetype == NT_BRIDGE && n->eq->portmac && MK_ISSELECTED (n->eq)) output_portmac (stdout, n) ; } } if (dumpipmac) { if (eq == NULL) { for (neq = mobj_head (eqmobj) ; neq != NULL ; neq = neq->next) { if(neq->ipmac && MK_ISSELECTED (neq)) output_ipmac (stdout, neq) ; } } else { if(eq->ipmac && MK_ISSELECTED (eq)) output_ipmac (stdout, eq) ; } } if (dumpstat) { for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { if (eq == NULL || n->eq == eq) { if (n->nodetype == NT_L2 && MK_ISSELECTED (n)) output_collect_L2 (stdout, n) ; if (n->nodetype == NT_L1 && MK_ISSELECTED (n)) output_collect_L1 (stdout, n) ; } } } sel_end () ; exit (0) ; }