forward2.cc
来自「BCAST Implementation for NS2」· CC 代码 · 共 611 行 · 第 1/2 页
CC
611 行
Forward2 *me = (Forward2 *)thunk; int tid; if(!me->_intransaction) return errh->error("Not in transaction"); if(!cp_integer(cp_uncomment(addr), (int *)&tid)) return errh->error("transaction ID required <%s>", String(addr).cc()); if(tid != me->_transactionID) return errh->error("transaction ID supplied <%s> does not match <%d>", String(addr).cc(), me->_transactionID); me->_intransaction = false; return 0;}/*** Delete all entries** Perform a write with the correct transactionID*/intForward2::write_handler_delete_all_entries(const String &addr, Element *, void *thunk, ErrorHandler *errh){ Forward2 *me = (Forward2 *)thunk; int tid; if(!me->_intransaction) return errh->error("Not in transaction"); if(!cp_integer(cp_uncomment(addr), (int *)&tid)) return errh->error("transaction ID required <%s>", String(addr).cc()); if(tid != me->_transactionID) return errh->error("transaction ID supplied <%s> does not match <%d>", String(addr).cc(), me->_transactionID); /* ** Zap the shadow routing table entry. */ me->_rt_shadow->zero(); return 0;}/*** Delete entry** Perform a write with the correct transactionID.** Followed by at least one entry to delete.*/intForward2::write_handler_delete_entry(const String &str, Element *, void *thunk, ErrorHandler *errh){ Forward2 *me = (Forward2 *)thunk; int tid; if(!me->_intransaction) return errh->error("Not in transaction"); Vector<String> conf; split_on_newline(str, conf); if(conf.size() < 1 || !cp_integer(conf[0], (int *)&tid)) return errh->error("transaction ID required <%s>", String(str).cc()); if(tid != me->_transactionID) return errh->error("transaction ID supplied <%s> does not match <%d>", String(str).cc(), me->_transactionID); /* ** Start from 1 as the first line was the TID. */ for(int i = 1; i < conf.size(); i++) { click_chatter("Deleting %s\n", conf[i].cc()); unsigned int dst, mask; Vector<String> words; cp_spacevec(conf[i], words); /* ** The options are: ** address/mask ** address/prefix */ /* ** Pick out the destination */ if(!cp_ip_prefix(words[0], (unsigned char *)&dst, (unsigned char *)&mask, true, me)) { errh->warning("bad argument line %d: %s should be addr/mask", i + 1, words[0].cc()); return -1; } /* XXX ** This method should return success or failure that needs to ** be propagated to the caller. */ me->_rt_shadow->del(dst, mask); } return 0;}/* XXX - A cut and paste of delete entry. Should write a common routing.** Add entry** Perform a write with the correct transactionID.** Followed by at least one entry to delete.*/intForward2::write_handler_add_entry(const String &str, Element *, void *thunk, ErrorHandler *errh){ Forward2 *me = (Forward2 *)thunk; int tid; if(!me->_intransaction) return errh->error("Not in transaction"); Vector<String> conf; split_on_newline(str, conf); if(conf.size() < 1 || !cp_integer(conf[0], (int *)&tid)) return errh->error("transaction ID required <%s>", String(str).cc()); if(tid != me->_transactionID) return errh->error("transaction ID supplied <%s> does not match <%d>", String(str).cc(), me->_transactionID); /* ** Start from 1 as the first line was the TID. */ click_chatter("Size %d\n", conf.size()); for(int i = 1; i < conf.size(); i++) { click_chatter("Adding %s\n", conf[i].cc()); unsigned int dst, mask; unsigned int gw = 0; int port; Vector<String> words; cp_spacevec(conf[i], words); /* ** The options are: ** address/mask [gw optional] port ** address/prefix [gw optional] port */ if(!((2 == words.size()) || (3 == words.size()))) { String tmp = conf[i]; errh->warning("bad argument line %d: %s", i + 1, tmp.cc()); return -1; } /* ** Pick out the destination */ if(!cp_ip_prefix(words[0], (unsigned char *)&dst, (unsigned char *)&mask, true, me)) { errh->warning("bad argument line %d: %s should be addr/mask", i + 1, words[0].cc()); return -1; } /* ** If there are three words pick out the optional gateway. */ if((3 == words.size())) { if(!cp_ip_address(words[1], (unsigned char *)&gw, me)) { errh->warning("bad argument line %d: %s should be addr", i + 1, words[1].cc()); return -1; } } /* ** port */ if(!cp_integer(words.back(), &port)) { errh->warning( "bad argument line %d: %s should be port number", i + 1, words.back().cc()); return -1; } /* XXX ** This method should return success or failure that needs to ** be propagated to the caller. */ me->_rt_shadow->add(dst, mask, gw, port); } return 0;}/*** This handler gives the whole routing table. The click_fti can** serialize it.**** start_reading and read_entry should be built on this interface.*/StringForward2::read_handler_table(Element *, void *thunk){ String result; Forward2 *me = (Forward2 *)thunk; if(false == me->_rt_current->start_table_read()) return String("Bogey"); IPV4address dst, mask, gw; int index; Rtable2::status status; while(me->_rt_current->next_table_read(dst, mask, gw, index, status)) {// click_chatter("Forward2::read_handler_table", dst.string().cc()); result += dst + "/" + String(mask.mask_length()) + "\t" + mask + "\t" + gw + " \t" + String(index) + "\n"; } return result;}intForward2::write_handler_lookup_route(const String &addr, Element *, void *thunk, ErrorHandler *errh){ IPV4address a; IPV4address dst; IPV4address mask; IPV4address gw; int oport; Forward2 *me = (Forward2 *)thunk; if(!cp_ip_address(cp_uncomment(addr), a.data())) return errh->error("bogus address <%s>", String(addr).cc()); if(!me->_rt_current->lookup(a, dst, mask, gw, oport)) return errh->error("lookup failed %s", String(addr).cc()); me->lookup_result = a + "\t" + dst + "/" + String(mask.mask_length()) + "\t" + gw + "\t" + String(oport) + String("\n"); return 0;}StringForward2::read_handler_lookup_route(Element *, void *thunk){ Forward2 *me = (Forward2 *)thunk; return me->lookup_result;}intForward2::write_handler_lookup_entry(const String &/*addr*/, Element *, void */*thunk*/, ErrorHandler */*errh*/){#if 0 IPV4address a; IPV4address dst; IPV4address mask; IPV4address gw; int oport; Forward2 *me = (Forward2 *)thunk; if(!cp_ip_address(cp_uncomment(addr), a.data())) return errh->error("bogus address <%s>", String(addr).cc()); if(!me->_rt_current->lookup(a, dst, mask, gw, oport)) return errh->error("lookup failed %s", String(addr).cc()); me->lookup_result = a + "\t" + dst + "/" + String(mask.mask_length()) + "\t" + gw + "\t" + String(oport) + String("\n");#endif return 0;}StringForward2::read_handler_lookup_entry(Element *, void */*thunk*/){#if 0 Forward2 *me = (Forward2 *)thunk; return me->lookup_result;#endif return String("Not implemented");}EXPORT_ELEMENT(Forward2)ELEMENT_REQUIRES(HoopyFrood)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?