21 #include "ns3/object-factory.h"
23 #include "ns3/names.h"
24 #include "ns3/ipv4-l3-protocol.h"
28 #include <arpa/inet.h>
45 m_radvd_if =
new std::map<std::string, std::string> ();
55 static TypeId tid = TypeId (
"ns3::QuaggaConfig")
57 .AddConstructor<QuaggaConfig> ()
91 os <<
"hostname zebra" << std::endl
92 <<
"password zebra" << std::endl
93 <<
"log stdout" << std::endl;
110 networks =
new std::map<std::string, uint32_t> ();
111 iflist =
new std::vector<uint32_t> ();
124 static TypeId tid = TypeId (
"ns3::OspfConfig")
125 .SetParent<Object> ()
126 .AddConstructor<OspfConfig> ()
139 networks->insert (std::map<std::string, uint32_t>::value_type (prefix, area));
157 os <<
"hostname zebra" << std::endl
158 <<
"password zebra" << std::endl
159 <<
"log stdout" << std::endl;
163 os <<
"debug ospf event " << std::endl;
164 os <<
"debug ospf nsm " << std::endl;
165 os <<
"debug ospf ism " << std::endl;
166 os <<
"debug ospf packet all " << std::endl;
169 for (std::vector<uint32_t>::iterator i =
iflist->begin ();
172 os <<
"interface ns3-device" << (*i) << std::endl;
175 os <<
"router ospf " << std::endl;
177 for (std::map<std::string, uint32_t>::iterator i =
networks->begin ();
180 os <<
" network " << (*i).first <<
" area " << (*i).second << std::endl;
182 os <<
" redistribute connected" << std::endl;
183 os <<
"!" << std::endl;
205 neighbors =
new std::vector<std::string> ();
207 networks =
new std::vector<std::string> ();
219 static TypeId tid = TypeId (
"ns3::BgpConfig")
220 .SetParent<Object> ()
221 .AddConstructor<BgpConfig> ()
236 std::stringstream ss;
237 ss <<
"192.168.0." <<
asn;
249 neighbor_asn->insert (std::map<std::string, uint32_t>::value_type (n, asn));
275 os <<
"hostname bgpd" << std::endl
276 <<
"password zebra" << std::endl
277 <<
"log stdout" << std::endl
278 <<
"debug bgp" << std::endl
279 <<
"debug bgp fsm" << std::endl
280 <<
"debug bgp events" << std::endl
281 <<
"debug bgp updates" << std::endl
282 <<
"router bgp " <<
asn << std::endl
283 <<
" bgp router-id " <<
router_id << std::endl;
284 for (std::vector<std::string>::iterator it =
neighbors->begin (); it !=
neighbors->end (); it++)
286 os <<
" neighbor " << *it <<
" remote-as " << (*neighbor_asn)[*it] << std::endl;
287 os <<
" neighbor " << *it <<
" advertisement-interval 5" << std::endl;
289 os <<
" redistribute connected" << std::endl;
291 os <<
" address-family ipv4 unicast" << std::endl;
292 for (std::vector<std::string>::iterator it =
neighbors->begin (); it !=
neighbors->end (); it++)
295 int ret = ::inet_pton (AF_INET, ((*it).c_str ()), &addr);
300 os <<
" neighbor " << *it <<
" activate" << std::endl;
301 os <<
" neighbor " << *it <<
" next-hop-self" << std::endl;
304 os <<
" neighbor " << *it <<
" default-originate" << std::endl;
307 for (std::vector<std::string>::iterator it =
networks->begin (); it !=
networks->end (); it++)
309 os <<
" network " << *it << std::endl;
311 os <<
" exit-address-family" << std::endl;
314 os <<
" address-family ipv6 unicast" << std::endl;
315 for (std::vector<std::string>::iterator it =
neighbors->begin (); it !=
neighbors->end (); it++)
317 struct in6_addr addr;
318 int ret = ::inet_pton (AF_INET6, ((*it).c_str ()), &addr);
323 os <<
" neighbor " << *it <<
" activate" << std::endl;
324 os <<
" neighbor " << *it <<
" next-hop-self" << std::endl;
327 os <<
" neighbor " << *it <<
" default-originate" << std::endl;
330 for (std::vector<std::string>::iterator it =
networks->begin (); it !=
networks->end (); it++)
332 os <<
" network " << *it << std::endl;
334 os <<
" redistribute connected" << std::endl;
335 os <<
" exit-address-family" << std::endl;
336 os <<
"!" << std::endl;
361 static TypeId tid = TypeId (
"ns3::Ospf6Config")
362 .SetParent<Object> ()
363 .AddConstructor<Ospf6Config> ()
389 os <<
"hostname ospf6d" << std::endl
390 <<
"password zebra" << std::endl
391 <<
"log stdout" << std::endl
392 <<
"service advanced-vty" << std::endl;
397 os <<
"debug ospf6 neighbor " << std::endl;
398 os <<
"debug ospf6 message all " << std::endl;
399 os <<
"debug ospf6 zebra " << std::endl;
400 os <<
"debug ospf6 interface " << std::endl;
403 for (std::vector<std::string>::iterator i =
m_enable_if->begin ();
406 os <<
"interface " << (*i) << std::endl;
407 os <<
" ipv6 ospf6 retransmit-interval 8" << std::endl;
408 os <<
"!" << std::endl;
411 for (std::vector<std::string>::iterator i =
m_enable_if->begin ();
416 os <<
"router ospf6" << std::endl;
419 os <<
" router-id 255.1.1." << (
m_router_id % 255) << std::endl;
420 os <<
" interface " << (*i) <<
" area 0.0.0.0" << std::endl;
421 os <<
" redistribute connected" << std::endl;
425 os <<
"!" << std::endl;
451 static TypeId tid = TypeId (
"ns3::RipConfig")
452 .SetParent<Object> ()
453 .AddConstructor<RipConfig> ()
479 os <<
"hostname ripd" << std::endl
480 <<
"password zebra" << std::endl
481 <<
"log stdout" << std::endl
482 <<
"service advanced-vty" << std::endl;
486 os <<
"debug rip events " << std::endl;
487 os <<
"debug rip packet send detail " << std::endl;
488 os <<
"debug rip packet recv detail " << std::endl;
489 os <<
"debug rip zebra " << std::endl;
492 for (std::vector<std::string>::iterator i =
m_enable_if->begin ();
497 os <<
"router rip" << std::endl;
500 os <<
" network " << (*i) << std::endl;
501 os <<
" redistribute connected" << std::endl;
505 os <<
"!" << std::endl;
531 static TypeId tid = TypeId (
"ns3::RipngConfig")
532 .SetParent<Object> ()
533 .AddConstructor<RipngConfig> ()
559 os <<
"hostname ripngd" << std::endl
560 <<
"password zebra" << std::endl
561 <<
"log stdout" << std::endl
562 <<
"service advanced-vty" << std::endl;
566 os <<
"debug ripng events " << std::endl;
567 os <<
"debug ripng packet send detail " << std::endl;
568 os <<
"debug ripng packet recv detail " << std::endl;
569 os <<
"debug ripng zebra " << std::endl;
572 for (std::vector<std::string>::iterator i =
m_enable_if->begin ();
577 os <<
"router ripng" << std::endl;
580 os <<
" network " << (*i) << std::endl;
581 os <<
" redistribute connected" << std::endl;
585 os <<
"!" << std::endl;
604 for (uint32_t i = 0; i < nodes.GetN (); i++)
606 Ptr<OspfConfig> ospf_conf = nodes.Get (i)->GetObject<
OspfConfig> ();
610 nodes.Get (i)->AggregateObject (ospf_conf);
613 ospf_conf->addNetwork (std::string (network), 0);
621 for (uint32_t i = 0; i < nodes.GetN (); i++)
623 Ptr<OspfConfig> ospf_conf = nodes.Get (i)->GetObject<
OspfConfig> ();
627 nodes.Get (i)->AggregateObject (ospf_conf);
629 ospf_conf->m_ospfdebug =
true;
638 for (uint32_t i = 0; i < nodes.GetN (); i++)
640 Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<
QuaggaConfig> ();
644 nodes.Get (i)->AggregateObject (zebra_conf);
646 zebra_conf->m_zebradebug =
true;
654 Ptr<QuaggaConfig> zebra_conf = node->GetObject<
QuaggaConfig> ();
658 node->AggregateObject (zebra_conf);
661 zebra_conf->m_radvd_if->insert (
662 std::map<std::string, std::string>::value_type (std::string (ifname), std::string (prefix)));
671 Ptr<QuaggaConfig> zebra_conf = node->GetObject<
QuaggaConfig> ();
675 node->AggregateObject (zebra_conf);
678 zebra_conf->m_haflag_if->push_back (std::string (ifname));
686 for (uint32_t i = 0; i < nodes.GetN (); i++)
688 Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<
QuaggaConfig> ();
692 nodes.Get (i)->AggregateObject (zebra_conf);
694 zebra_conf->m_usemanualconf =
true;
704 for (uint32_t i = 0; i < nodes.GetN (); i++)
706 Ptr<BgpConfig> bgp_conf = nodes.Get (i)->GetObject<
BgpConfig> ();
709 bgp_conf = CreateObject<BgpConfig> ();
710 bgp_conf->
SetAsn (nodes.Get (i)->GetId ());
711 nodes.Get (i)->AggregateObject (bgp_conf);
721 Ptr<BgpConfig> bgp_conf = node->GetObject<
BgpConfig> ();
726 return bgp_conf->
GetAsn ();
732 Ptr<BgpConfig> bgp_conf = node->GetObject<
BgpConfig> ();
735 bgp_conf = CreateObject<BgpConfig> ();
736 bgp_conf->
SetAsn (node->GetId ());
737 node->AggregateObject (bgp_conf);
739 bgp_conf->AddNeighbor (neighbor, asn);
747 for (uint32_t i = 0; i < nodes.GetN (); i++)
749 Ptr<Ospf6Config> ospf6_conf = nodes.Get (i)->GetObject<
Ospf6Config> ();
753 nodes.Get (i)->AggregateObject (ospf6_conf);
756 ospf6_conf->m_enable_if->push_back (std::string (ifname));
757 ospf6_conf->m_router_id = i;
766 for (uint32_t i = 0; i < nodes.GetN (); i++)
768 Ptr<Ospf6Config> ospf6_conf = nodes.Get (i)->GetObject<
Ospf6Config> ();
772 nodes.Get (i)->AggregateObject (ospf6_conf);
774 ospf6_conf->m_ospf6debug =
true;
783 for (uint32_t i = 0; i < nodes.GetN (); i++)
785 Ptr<RipConfig> rip_conf = nodes.Get (i)->GetObject<
RipConfig> ();
789 nodes.Get (i)->AggregateObject (rip_conf);
792 rip_conf->m_enable_if->push_back (std::string (ifname));
801 for (uint32_t i = 0; i < nodes.GetN (); i++)
803 Ptr<RipConfig> rip_conf = nodes.Get (i)->GetObject<
RipConfig> ();
807 nodes.Get (i)->AggregateObject (rip_conf);
809 rip_conf->m_ripdebug =
true;
818 for (uint32_t i = 0; i < nodes.GetN (); i++)
820 Ptr<RipngConfig> ripng_conf = nodes.Get (i)->GetObject<
RipngConfig> ();
824 nodes.Get (i)->AggregateObject (ripng_conf);
827 ripng_conf->m_enable_if->push_back (std::string (ifname));
836 for (uint32_t i = 0; i < nodes.GetN (); i++)
838 Ptr<RipngConfig> ripng_conf = nodes.Get (i)->GetObject<
RipngConfig> ();
842 nodes.Get (i)->AggregateObject (ripng_conf);
844 ripng_conf->m_ripngdebug =
true;
852 Ptr<QuaggaConfig> zebra_conf = node->GetObject<
QuaggaConfig> ();
855 std::stringstream conf_dir, conf_file;
857 conf_dir <<
"files-" << node->GetId () <<
"";
858 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
860 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
861 conf_dir <<
"/local/";
862 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
864 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
866 conf_file << conf_dir.str () <<
"/zebra.conf";
867 zebra_conf->
SetFilename (
"/usr/local/etc/zebra.conf");
869 if (zebra_conf->m_usemanualconf)
875 conf.open (conf_file.str ().c_str ());
877 if (zebra_conf->m_zebradebug)
879 conf <<
"debug zebra kernel" << std::endl;
880 conf <<
"debug zebra events" << std::endl;
881 conf <<
"debug zebra packet" << std::endl;
886 for (std::map<std::string, std::string>::iterator i = zebra_conf->m_radvd_if->begin ();
887 i != zebra_conf->m_radvd_if->end (); ++i)
889 conf <<
"interface " << (*i).first << std::endl;
890 conf <<
" ipv6 nd ra-interval 5" << std::endl;
891 if ((*i).second.length () != 0)
893 conf <<
" ipv6 nd prefix " << (*i).second <<
" 300 150" << std::endl;
895 conf <<
" no ipv6 nd suppress-ra" << std::endl;
896 conf <<
"!" << std::endl;
900 for (std::vector<std::string>::iterator i = zebra_conf->m_haflag_if->begin ();
901 i != zebra_conf->m_haflag_if->end (); ++i)
903 conf <<
"interface " << (*i) << std::endl;
904 conf <<
" ipv6 nd home-agent-config-flag" << std::endl;
905 conf <<
"!" << std::endl;
914 NS_LOG_FUNCTION (node);
916 Ptr<OspfConfig> ospf_conf = node->GetObject<
OspfConfig> ();
920 std::stringstream conf_dir, conf_file;
922 conf_dir <<
"files-" << node->GetId () <<
"";
923 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
925 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
926 conf_dir <<
"/local/";
927 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
929 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
931 conf_file << conf_dir.str () <<
"/ospfd.conf";
932 ospf_conf->SetFilename (
"/usr/local/etc/ospfd.conf");
935 conf.open (conf_file.str ().c_str ());
936 ospf_conf->Print (conf);
944 Ptr<BgpConfig> bgp_conf = node->GetObject<
BgpConfig> ();
947 std::stringstream conf_dir, conf_file;
949 conf_dir <<
"files-" << node->GetId () <<
"";
950 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
952 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
953 conf_dir <<
"/local/";
954 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
956 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
958 conf_file << conf_dir.str () <<
"/bgpd.conf";
959 bgp_conf->
SetFilename (
"/usr/local/etc/bgpd.conf");
962 conf.open (conf_file.str ().c_str ());
963 bgp_conf->Print (conf);
971 Ptr<Ospf6Config> ospf6_conf = node->GetObject<
Ospf6Config> ();
974 std::stringstream conf_dir, conf_file;
976 conf_dir <<
"files-" << node->GetId () <<
"";
977 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
979 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
980 conf_dir <<
"/local/";
981 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
983 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
985 conf_file << conf_dir.str () <<
"/ospf6d.conf";
986 ospf6_conf->
SetFilename (
"/usr/local/etc/ospf6d.conf");
988 conf.open (conf_file.str ().c_str ());
989 ospf6_conf->Print (conf);
996 NS_LOG_FUNCTION (node);
998 Ptr<RipConfig> rip_conf = node->GetObject<
RipConfig> ();
1001 std::stringstream conf_dir, conf_file;
1003 conf_dir <<
"files-" << node->GetId () <<
"";
1004 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1005 conf_dir <<
"/usr/";
1006 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1007 conf_dir <<
"/local/";
1008 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1009 conf_dir <<
"/etc/";
1010 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1012 conf_file << conf_dir.str () <<
"/ripd.conf";
1013 rip_conf->
SetFilename (
"/usr/local/etc/ripd.conf");
1016 conf.open (conf_file.str ().c_str ());
1017 rip_conf->Print (conf);
1024 NS_LOG_FUNCTION (node);
1026 Ptr<RipngConfig> ripng_conf = node->GetObject<
RipngConfig> ();
1029 std::stringstream conf_dir, conf_file;
1031 conf_dir <<
"files-" << node->GetId () <<
"";
1032 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1033 conf_dir <<
"/usr/";
1034 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1035 conf_dir <<
"/local/";
1036 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1037 conf_dir <<
"/etc/";
1038 ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
1040 conf_file << conf_dir.str () <<
"/ripngd.conf";
1041 ripng_conf->
SetFilename (
"/usr/local/etc/ripngd.conf");
1044 conf.open (conf_file.str ().c_str ());
1045 ripng_conf->Print (conf);
1049 ApplicationContainer
1055 ApplicationContainer
1058 Ptr<Node> node = Names::Find<Node> (nodeName);
1062 ApplicationContainer
1065 ApplicationContainer apps;
1066 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
1074 ApplicationContainer
1078 ApplicationContainer apps;
1080 Ptr<QuaggaConfig> zebra_conf = node->GetObject<
QuaggaConfig> ();
1084 node->AggregateObject (zebra_conf);
1088 process.
AddArguments (
"-f", zebra_conf->GetFilename ());
1089 process.
AddArguments (
"-i",
"/usr/local/etc/zebra.pid");
1091 apps.Add (process.
Install (node));
1092 apps.Get (0)->SetStartTime (Seconds (1.0 + 0.01 * node->GetId ()));
1093 node->AddApplication (apps.Get (0));
1095 Ptr<OspfConfig> ospf_conf = node->GetObject<
OspfConfig> ();
1103 process.
AddArguments (
"-f", ospf_conf->GetFilename ());
1104 process.
AddArguments (
"-i",
"/usr/local/etc/ospfd.pid");
1105 apps.Add (process.
Install (node));
1106 apps.Get (1)->SetStartTime (Seconds (5.0 + 0.1 * node->GetId ()));
1107 node->AddApplication (apps.Get (1));
1110 Ptr<BgpConfig> bgp_conf = node->GetObject<
BgpConfig> ();
1118 process.
AddArguments (
"-i",
"/usr/local/etc/bgpd.pid");
1119 apps = process.
Install (node);
1120 apps.Get (0)->SetStartTime (Seconds (5.0 + 0.3 * node->GetId ()));
1122 node->AddApplication (apps.Get (0));
1125 Ptr<Ospf6Config> ospf6_conf = node->GetObject<
Ospf6Config> ();
1132 process.
AddArguments (
"-f", ospf6_conf->GetFilename ());
1133 process.
AddArguments (
"-i",
"/usr/local/etc/ospf6d.pid");
1134 apps = process.
Install (node);
1135 apps.Get (0)->SetStartTime (Seconds (5.0 + 0.5 * node->GetId ()));
1136 node->AddApplication (apps.Get (0));
1139 Ptr<RipConfig> rip_conf = node->GetObject<
RipConfig> ();
1147 process.
AddArguments (
"-i",
"/usr/local/etc/ripd.pid");
1148 apps = process.
Install (node);
1149 apps.Get (0)->SetStartTime (Seconds (5.0 + 0.5 * node->GetId ()));
1150 node->AddApplication (apps.Get (0));
1153 Ptr<RipngConfig> ripng_conf = node->GetObject<
RipngConfig> ();
1160 process.
AddArguments (
"-f", ripng_conf->GetFilename ());
1161 process.
AddArguments (
"-i",
"/usr/local/etc/ripngd.pid");
1162 apps = process.
Install (node);
1163 apps.Get (0)->SetStartTime (Seconds (5.0 + 0.5 * node->GetId ()));
1164 node->AddApplication (apps.Get (0));