ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quagga-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Hajime Tazaki, NICT
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Hajime Tazaki <tazaki@nict.go.jp>
19  */
20 
21 #include "ns3/object-factory.h"
22 #include "quagga-helper.h"
23 #include "ns3/names.h"
24 #include "ns3/ipv4-l3-protocol.h"
25 #include <fstream>
26 #include <sys/stat.h>
27 #include "ns3/log.h"
28 #include <arpa/inet.h>
29 
30 NS_LOG_COMPONENT_DEFINE ("QuaggaHelper");
31 
32 namespace ns3 {
33 
34 class QuaggaConfig : public Object
35 {
36 private:
37  static int index;
38  std::string router_id;
39  std::map<std::string, uint32_t> *networks;
40 public:
42  : m_zebradebug (false),
43  m_usemanualconf (false)
44  {
45  m_radvd_if = new std::map<std::string, std::string> ();
46  m_haflag_if = new std::vector<std::string> ();
47  }
49  {
50  }
51 
52  static TypeId
53  GetTypeId (void)
54  {
55  static TypeId tid = TypeId ("ns3::QuaggaConfig")
56  .SetParent<Object> ()
57  .AddConstructor<QuaggaConfig> ()
58  ;
59  return tid;
60  }
61  TypeId
62  GetInstanceTypeId (void) const
63  {
64  return GetTypeId ();
65  }
66 
67  void
68  SetFilename (const std::string &filename)
69  {
70  m_filename = filename;
71  }
72 
73  std::string
74  GetFilename () const
75  {
76  return m_filename;
77  }
78 
81  std::map<std::string, std::string> *m_radvd_if;
82  std::vector<std::string> *m_haflag_if;
83 
84  std::string m_filename;
85 
86  std::vector<uint32_t> iflist;
87 
88  virtual void
89  Print (std::ostream& os) const
90  {
91  os << "hostname zebra" << std::endl
92  << "password zebra" << std::endl
93  << "log stdout" << std::endl;
94  }
95 };
96 std::ostream& operator << (std::ostream& os, QuaggaConfig const& config)
97 {
98  config.Print (os);
99  return os;
100 }
101 
102 class OspfConfig : public Object
103 {
104 private:
105  std::map<std::string, uint32_t> *networks;
106 public:
108  : m_ospfdebug (false)
109  {
110  networks = new std::map<std::string, uint32_t> ();
111  iflist = new std::vector<uint32_t> ();
112  }
114  {
115  delete networks;
116  delete iflist;
117  }
118 
120 
121  static TypeId
122  GetTypeId (void)
123  {
124  static TypeId tid = TypeId ("ns3::OspfConfig")
125  .SetParent<Object> ()
126  .AddConstructor<OspfConfig> ()
127  ;
128  return tid;
129  }
130  TypeId
131  GetInstanceTypeId (void) const
132  {
133  return GetTypeId ();
134  }
135 
136  void
137  addNetwork (std::string prefix, uint32_t area)
138  {
139  networks->insert (std::map<std::string, uint32_t>::value_type (prefix, area));
140  }
141 
142  void
143  SetFilename (const std::string &filename)
144  {
145  m_filename = filename;
146  }
147 
148  std::string
149  GetFilename () const
150  {
151  return m_filename;
152  }
153 
154  virtual void
155  Print (std::ostream& os) const
156  {
157  os << "hostname zebra" << std::endl
158  << "password zebra" << std::endl
159  << "log stdout" << std::endl;
160  if (m_ospfdebug)
161  {
162  //os << "log trap errors" << 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;
167  }
168 
169  for (std::vector<uint32_t>::iterator i = iflist->begin ();
170  i != iflist->end (); ++i)
171  {
172  os << "interface ns3-device" << (*i) << std::endl;
173  }
174 
175  os << "router ospf " << std::endl;
176  // os << " ospf router-id " << m_routerId << std::endl;
177  for (std::map<std::string, uint32_t>::iterator i = networks->begin ();
178  i != networks->end (); ++i)
179  {
180  os << " network " << (*i).first << " area " << (*i).second << std::endl;
181  }
182  os << " redistribute connected" << std::endl;
183  os << "!" << std::endl;
184  }
185  std::vector<uint32_t> *iflist;
186  std::string m_filename;
187  uint32_t m_routerId;
188 };
189 
190 class BgpConfig : public Object
191 {
192 private:
193  static int index;
194  uint32_t asn;
195  std::string router_id;
196  std::vector<std::string> *neighbors;
197  std::map<std::string, uint32_t> *neighbor_asn;
198  std::vector<std::string> *networks;
200  std::string m_filename;
201 
202 public:
204  {
205  neighbors = new std::vector<std::string> ();
206  neighbor_asn = new std::map<std::string, uint32_t> ();
207  networks = new std::vector<std::string> ();
208  isDefaultOriginate = false;
209  }
211  {
212  delete neighbors;
213  delete neighbor_asn;
214  delete networks;
215  }
216  static TypeId
217  GetTypeId (void)
218  {
219  static TypeId tid = TypeId ("ns3::BgpConfig")
220  .SetParent<Object> ()
221  .AddConstructor<BgpConfig> ()
222  ;
223  return tid;
224  }
225  TypeId
226  GetInstanceTypeId (void) const
227  {
228  return GetTypeId ();
229  }
230 
231  void
232  SetAsn (uint32_t lasn)
233  {
234  asn = lasn + 1;
235  {
236  std::stringstream ss;
237  ss << "192.168.0." << asn;
238  router_id = ss.str ();
239  }
240  }
241 
242  uint32_t GetAsn ()
243  {
244  return asn;
245  }
246  void AddNeighbor (std::string n, uint32_t asn)
247  {
248  neighbors->push_back (n);
249  neighbor_asn->insert (std::map<std::string, uint32_t>::value_type (n, asn));
250  }
251  void addNetwork (std::string n)
252  {
253  networks->push_back (n);
254  }
256  {
257  isDefaultOriginate = true;
258  }
259 
260  void
261  SetFilename (const std::string &filename)
262  {
263  m_filename = filename;
264  }
265 
266  std::string
267  GetFilename () const
268  {
269  return m_filename;
270  }
271 
272  virtual void
273  Print (std::ostream& os) const
274  {
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++)
285  {
286  os << " neighbor " << *it << " remote-as " << (*neighbor_asn)[*it] << std::endl;
287  os << " neighbor " << *it << " advertisement-interval 5" << std::endl;
288  }
289  os << " redistribute connected" << std::endl;
290  // IPv4
291  os << " address-family ipv4 unicast" << std::endl;
292  for (std::vector<std::string>::iterator it = neighbors->begin (); it != neighbors->end (); it++)
293  {
294  struct in_addr addr;
295  int ret = ::inet_pton (AF_INET, ((*it).c_str ()), &addr);
296  if (!ret)
297  {
298  continue;
299  }
300  os << " neighbor " << *it << " activate" << std::endl;
301  os << " neighbor " << *it << " next-hop-self" << std::endl;
302  if (isDefaultOriginate == true)
303  {
304  os << " neighbor " << *it << " default-originate" << std::endl;
305  }
306  }
307  for (std::vector<std::string>::iterator it = networks->begin (); it != networks->end (); it++)
308  {
309  os << " network " << *it << std::endl;
310  }
311  os << " exit-address-family" << std::endl;
312 
313  // IPv6
314  os << " address-family ipv6 unicast" << std::endl;
315  for (std::vector<std::string>::iterator it = neighbors->begin (); it != neighbors->end (); it++)
316  {
317  struct in6_addr addr;
318  int ret = ::inet_pton (AF_INET6, ((*it).c_str ()), &addr);
319  if (!ret)
320  {
321  continue;
322  }
323  os << " neighbor " << *it << " activate" << std::endl;
324  os << " neighbor " << *it << " next-hop-self" << std::endl;
325  if (isDefaultOriginate == true)
326  {
327  os << " neighbor " << *it << " default-originate" << std::endl;
328  }
329  }
330  for (std::vector<std::string>::iterator it = networks->begin (); it != networks->end (); it++)
331  {
332  os << " network " << *it << std::endl;
333  }
334  os << " redistribute connected" << std::endl;
335  os << " exit-address-family" << std::endl;
336  os << "!" << std::endl;
337  }
338 };
339 
340 class Ospf6Config : public Object
341 {
342 private:
343 public:
344  std::vector<std::string> *m_enable_if;
346  uint32_t m_router_id;
347  std::string m_filename;
348 
350  {
351  m_enable_if = new std::vector<std::string> ();
352  m_ospf6debug = false;
353  }
355  {
356  delete m_enable_if;
357  }
358  static TypeId
359  GetTypeId (void)
360  {
361  static TypeId tid = TypeId ("ns3::Ospf6Config")
362  .SetParent<Object> ()
363  .AddConstructor<Ospf6Config> ()
364  ;
365  return tid;
366  }
367  TypeId
368  GetInstanceTypeId (void) const
369  {
370  return GetTypeId ();
371  }
372 
373 
374  void
375  SetFilename (const std::string &filename)
376  {
377  m_filename = filename;
378  }
379 
380  std::string
381  GetFilename () const
382  {
383  return m_filename;
384  }
385 
386  virtual void
387  Print (std::ostream& os) const
388  {
389  os << "hostname ospf6d" << std::endl
390  << "password zebra" << std::endl
391  << "log stdout" << std::endl
392  << "service advanced-vty" << std::endl;
393 
394 
395  if (m_ospf6debug)
396  {
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;
401  }
402 
403  for (std::vector<std::string>::iterator i = m_enable_if->begin ();
404  i != m_enable_if->end (); ++i)
405  {
406  os << "interface " << (*i) << std::endl;
407  os << " ipv6 ospf6 retransmit-interval 8" << std::endl;
408  os << "!" << std::endl;
409  }
410 
411  for (std::vector<std::string>::iterator i = m_enable_if->begin ();
412  i != m_enable_if->end (); ++i)
413  {
414  if (i == m_enable_if->begin ())
415  {
416  os << "router ospf6" << std::endl;
417  }
418 
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;
422 
423  if (i == m_enable_if->begin ())
424  {
425  os << "!" << std::endl;
426  }
427  }
428  }
429 };
430 
431 class RipConfig : public Object
432 {
433 private:
434 public:
435  std::vector<std::string> *m_enable_if;
437  std::string m_filename;
438 
440  {
441  m_enable_if = new std::vector<std::string> ();
442  m_ripdebug = false;
443  }
445  {
446  delete m_enable_if;
447  }
448  static TypeId
449  GetTypeId (void)
450  {
451  static TypeId tid = TypeId ("ns3::RipConfig")
452  .SetParent<Object> ()
453  .AddConstructor<RipConfig> ()
454  ;
455  return tid;
456  }
457  TypeId
458  GetInstanceTypeId (void) const
459  {
460  return GetTypeId ();
461  }
462 
463 
464  void
465  SetFilename (const std::string &filename)
466  {
467  m_filename = filename;
468  }
469 
470  std::string
471  GetFilename () const
472  {
473  return m_filename;
474  }
475 
476  virtual void
477  Print (std::ostream& os) const
478  {
479  os << "hostname ripd" << std::endl
480  << "password zebra" << std::endl
481  << "log stdout" << std::endl
482  << "service advanced-vty" << std::endl;
483 
484  if (m_ripdebug)
485  {
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;
490  }
491 
492  for (std::vector<std::string>::iterator i = m_enable_if->begin ();
493  i != m_enable_if->end (); ++i)
494  {
495  if (i == m_enable_if->begin ())
496  {
497  os << "router rip" << std::endl;
498  }
499 
500  os << " network " << (*i) << std::endl;
501  os << " redistribute connected" << std::endl;
502 
503  if (i == m_enable_if->begin ())
504  {
505  os << "!" << std::endl;
506  }
507  }
508  }
509 };
510 
511 class RipngConfig : public Object
512 {
513 private:
514 public:
515  std::vector<std::string> *m_enable_if;
517  std::string m_filename;
518 
520  {
521  m_enable_if = new std::vector<std::string> ();
522  m_ripngdebug = false;
523  }
525  {
526  delete m_enable_if;
527  }
528  static TypeId
529  GetTypeId (void)
530  {
531  static TypeId tid = TypeId ("ns3::RipngConfig")
532  .SetParent<Object> ()
533  .AddConstructor<RipngConfig> ()
534  ;
535  return tid;
536  }
537  TypeId
538  GetInstanceTypeId (void) const
539  {
540  return GetTypeId ();
541  }
542 
543 
544  void
545  SetFilename (const std::string &filename)
546  {
547  m_filename = filename;
548  }
549 
550  std::string
551  GetFilename () const
552  {
553  return m_filename;
554  }
555 
556  virtual void
557  Print (std::ostream& os) const
558  {
559  os << "hostname ripngd" << std::endl
560  << "password zebra" << std::endl
561  << "log stdout" << std::endl
562  << "service advanced-vty" << std::endl;
563 
564  if (m_ripngdebug)
565  {
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;
570  }
571 
572  for (std::vector<std::string>::iterator i = m_enable_if->begin ();
573  i != m_enable_if->end (); ++i)
574  {
575  if (i == m_enable_if->begin ())
576  {
577  os << "router ripng" << std::endl;
578  }
579 
580  os << " network " << (*i) << std::endl;
581  os << " redistribute connected" << std::endl;
582 
583  if (i == m_enable_if->begin ())
584  {
585  os << "!" << std::endl;
586  }
587  }
588  }
589 };
590 
592 {
593 }
594 
595 void
596 QuaggaHelper::SetAttribute (std::string name, const AttributeValue &value)
597 {
598 }
599 
600 // OSPF
601 void
602 QuaggaHelper::EnableOspf (NodeContainer nodes, const char *network)
603 {
604  for (uint32_t i = 0; i < nodes.GetN (); i++)
605  {
606  Ptr<OspfConfig> ospf_conf = nodes.Get (i)->GetObject<OspfConfig> ();
607  if (!ospf_conf)
608  {
609  ospf_conf = new OspfConfig ();
610  nodes.Get (i)->AggregateObject (ospf_conf);
611  }
612 
613  ospf_conf->addNetwork (std::string (network), 0);
614  }
615  return;
616 }
617 
618 void
619 QuaggaHelper::EnableOspfDebug (NodeContainer nodes)
620 {
621  for (uint32_t i = 0; i < nodes.GetN (); i++)
622  {
623  Ptr<OspfConfig> ospf_conf = nodes.Get (i)->GetObject<OspfConfig> ();
624  if (!ospf_conf)
625  {
626  ospf_conf = new OspfConfig ();
627  nodes.Get (i)->AggregateObject (ospf_conf);
628  }
629  ospf_conf->m_ospfdebug = true;
630  }
631  return;
632 }
633 
634 
635 void
636 QuaggaHelper::EnableZebraDebug (NodeContainer nodes)
637 {
638  for (uint32_t i = 0; i < nodes.GetN (); i++)
639  {
640  Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig> ();
641  if (!zebra_conf)
642  {
643  zebra_conf = new QuaggaConfig ();
644  nodes.Get (i)->AggregateObject (zebra_conf);
645  }
646  zebra_conf->m_zebradebug = true;
647  }
648  return;
649 }
650 
651 void
652 QuaggaHelper::EnableRadvd (Ptr<Node> node, const char *ifname, const char *prefix)
653 {
654  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig> ();
655  if (!zebra_conf)
656  {
657  zebra_conf = new QuaggaConfig ();
658  node->AggregateObject (zebra_conf);
659  }
660 
661  zebra_conf->m_radvd_if->insert (
662  std::map<std::string, std::string>::value_type (std::string (ifname), std::string (prefix)));
663 
664  return;
665 }
666 
667 
668 void
669 QuaggaHelper::EnableHomeAgentFlag (Ptr<Node> node, const char *ifname)
670 {
671  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig> ();
672  if (!zebra_conf)
673  {
674  zebra_conf = new QuaggaConfig ();
675  node->AggregateObject (zebra_conf);
676  }
677 
678  zebra_conf->m_haflag_if->push_back (std::string (ifname));
679 
680  return;
681 }
682 
683 void
685 {
686  for (uint32_t i = 0; i < nodes.GetN (); i++)
687  {
688  Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig> ();
689  if (!zebra_conf)
690  {
691  zebra_conf = new QuaggaConfig ();
692  nodes.Get (i)->AggregateObject (zebra_conf);
693  }
694  zebra_conf->m_usemanualconf = true;
695  }
696  return;
697 }
698 
699 
700 // BGP
701 void
702 QuaggaHelper::EnableBgp (NodeContainer nodes)
703 {
704  for (uint32_t i = 0; i < nodes.GetN (); i++)
705  {
706  Ptr<BgpConfig> bgp_conf = nodes.Get (i)->GetObject<BgpConfig> ();
707  if (!bgp_conf)
708  {
709  bgp_conf = CreateObject<BgpConfig> ();
710  bgp_conf->SetAsn (nodes.Get (i)->GetId ());
711  nodes.Get (i)->AggregateObject (bgp_conf);
712  }
713  }
714 
715  return;
716 }
717 
718 uint32_t
719 QuaggaHelper::GetAsn (Ptr<Node> node)
720 {
721  Ptr<BgpConfig> bgp_conf = node->GetObject<BgpConfig> ();
722  if (!bgp_conf)
723  {
724  return 0;
725  }
726  return bgp_conf->GetAsn ();
727 }
728 
729 void
730 QuaggaHelper::BgpAddNeighbor (Ptr<Node> node, std::string neighbor, uint32_t asn)
731 {
732  Ptr<BgpConfig> bgp_conf = node->GetObject<BgpConfig> ();
733  if (!bgp_conf)
734  {
735  bgp_conf = CreateObject<BgpConfig> ();
736  bgp_conf->SetAsn (node->GetId ());
737  node->AggregateObject (bgp_conf);
738  }
739  bgp_conf->AddNeighbor (neighbor, asn);
740  return;
741 }
742 
743 // OSPF6
744 void
745 QuaggaHelper::EnableOspf6 (NodeContainer nodes, const char *ifname)
746 {
747  for (uint32_t i = 0; i < nodes.GetN (); i++)
748  {
749  Ptr<Ospf6Config> ospf6_conf = nodes.Get (i)->GetObject<Ospf6Config> ();
750  if (!ospf6_conf)
751  {
752  ospf6_conf = new Ospf6Config ();
753  nodes.Get (i)->AggregateObject (ospf6_conf);
754  }
755 
756  ospf6_conf->m_enable_if->push_back (std::string (ifname));
757  ospf6_conf->m_router_id = i;
758  }
759 
760  return;
761 }
762 
763 void
764 QuaggaHelper::EnableOspf6Debug (NodeContainer nodes)
765 {
766  for (uint32_t i = 0; i < nodes.GetN (); i++)
767  {
768  Ptr<Ospf6Config> ospf6_conf = nodes.Get (i)->GetObject<Ospf6Config> ();
769  if (!ospf6_conf)
770  {
771  ospf6_conf = new Ospf6Config ();
772  nodes.Get (i)->AggregateObject (ospf6_conf);
773  }
774  ospf6_conf->m_ospf6debug = true;
775  }
776  return;
777 }
778 
779 // RIP
780 void
781 QuaggaHelper::EnableRip (NodeContainer nodes, const char *ifname)
782 {
783  for (uint32_t i = 0; i < nodes.GetN (); i++)
784  {
785  Ptr<RipConfig> rip_conf = nodes.Get (i)->GetObject<RipConfig> ();
786  if (!rip_conf)
787  {
788  rip_conf = new RipConfig ();
789  nodes.Get (i)->AggregateObject (rip_conf);
790  }
791 
792  rip_conf->m_enable_if->push_back (std::string (ifname));
793  }
794 
795  return;
796 }
797 
798 void
799 QuaggaHelper::EnableRipDebug (NodeContainer nodes)
800 {
801  for (uint32_t i = 0; i < nodes.GetN (); i++)
802  {
803  Ptr<RipConfig> rip_conf = nodes.Get (i)->GetObject<RipConfig> ();
804  if (!rip_conf)
805  {
806  rip_conf = new RipConfig ();
807  nodes.Get (i)->AggregateObject (rip_conf);
808  }
809  rip_conf->m_ripdebug = true;
810  }
811  return;
812 }
813 
814 // RIPNG
815 void
816 QuaggaHelper::EnableRipng (NodeContainer nodes, const char *ifname)
817 {
818  for (uint32_t i = 0; i < nodes.GetN (); i++)
819  {
820  Ptr<RipngConfig> ripng_conf = nodes.Get (i)->GetObject<RipngConfig> ();
821  if (!ripng_conf)
822  {
823  ripng_conf = new RipngConfig ();
824  nodes.Get (i)->AggregateObject (ripng_conf);
825  }
826 
827  ripng_conf->m_enable_if->push_back (std::string (ifname));
828  }
829 
830  return;
831 }
832 
833 void
834 QuaggaHelper::EnableRipngDebug (NodeContainer nodes)
835 {
836  for (uint32_t i = 0; i < nodes.GetN (); i++)
837  {
838  Ptr<RipngConfig> ripng_conf = nodes.Get (i)->GetObject<RipngConfig> ();
839  if (!ripng_conf)
840  {
841  ripng_conf = new RipngConfig ();
842  nodes.Get (i)->AggregateObject (ripng_conf);
843  }
844  ripng_conf->m_ripngdebug = true;
845  }
846  return;
847 }
848 
849 void
851 {
852  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig> ();
853 
854  // config generation
855  std::stringstream conf_dir, conf_file;
856  // FIXME XXX
857  conf_dir << "files-" << node->GetId () << "";
858  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
859  conf_dir << "/usr/";
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);
863  conf_dir << "/etc/";
864  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
865 
866  conf_file << conf_dir.str () << "/zebra.conf";
867  zebra_conf->SetFilename ("/usr/local/etc/zebra.conf");
868 
869  if (zebra_conf->m_usemanualconf)
870  {
871  return;
872  }
873 
874  std::ofstream conf;
875  conf.open (conf_file.str ().c_str ());
876  conf << *zebra_conf;
877  if (zebra_conf->m_zebradebug)
878  {
879  conf << "debug zebra kernel" << std::endl;
880  conf << "debug zebra events" << std::endl;
881  conf << "debug zebra packet" << std::endl;
882  // conf << "debug zebra route" << std::endl;
883  }
884 
885  // radvd
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)
888  {
889  conf << "interface " << (*i).first << std::endl;
890  conf << " ipv6 nd ra-interval 5" << std::endl;
891  if ((*i).second.length () != 0)
892  {
893  conf << " ipv6 nd prefix " << (*i).second << " 300 150" << std::endl;
894  }
895  conf << " no ipv6 nd suppress-ra" << std::endl;
896  conf << "!" << std::endl;
897  }
898 
899  // ha flag
900  for (std::vector<std::string>::iterator i = zebra_conf->m_haflag_if->begin ();
901  i != zebra_conf->m_haflag_if->end (); ++i)
902  {
903  conf << "interface " << (*i) << std::endl;
904  conf << " ipv6 nd home-agent-config-flag" << std::endl;
905  conf << "!" << std::endl;
906  }
907 
908  conf.close ();
909 }
910 
911 void
913 {
914  NS_LOG_FUNCTION (node);
915 
916  Ptr<OspfConfig> ospf_conf = node->GetObject<OspfConfig> ();
917  ospf_conf->m_routerId = 1 + node->GetId ();
918 
919  // config generation
920  std::stringstream conf_dir, conf_file;
921  // FIXME XXX
922  conf_dir << "files-" << node->GetId () << "";
923  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
924  conf_dir << "/usr/";
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);
928  conf_dir << "/etc/";
929  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
930 
931  conf_file << conf_dir.str () << "/ospfd.conf";
932  ospf_conf->SetFilename ("/usr/local/etc/ospfd.conf");
933 
934  std::ofstream conf;
935  conf.open (conf_file.str ().c_str ());
936  ospf_conf->Print (conf);
937  conf.close ();
938 
939 }
940 
941 void
943 {
944  Ptr<BgpConfig> bgp_conf = node->GetObject<BgpConfig> ();
945 
946  // config generation
947  std::stringstream conf_dir, conf_file;
948  // FIXME XXX
949  conf_dir << "files-" << node->GetId () << "";
950  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
951  conf_dir << "/usr/";
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);
955  conf_dir << "/etc/";
956  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
957 
958  conf_file << conf_dir.str () << "/bgpd.conf";
959  bgp_conf->SetFilename ("/usr/local/etc/bgpd.conf");
960 
961  std::ofstream conf;
962  conf.open (conf_file.str ().c_str ());
963  bgp_conf->Print (conf);
964  conf.close ();
965 
966 }
967 
968 void
970 {
971  Ptr<Ospf6Config> ospf6_conf = node->GetObject<Ospf6Config> ();
972 
973  // config generation
974  std::stringstream conf_dir, conf_file;
975  // FIXME XXX
976  conf_dir << "files-" << node->GetId () << "";
977  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
978  conf_dir << "/usr/";
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);
982  conf_dir << "/etc/";
983  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
984 
985  conf_file << conf_dir.str () << "/ospf6d.conf";
986  ospf6_conf->SetFilename ("/usr/local/etc/ospf6d.conf");
987  std::ofstream conf;
988  conf.open (conf_file.str ().c_str ());
989  ospf6_conf->Print (conf);
990  conf.close ();
991 }
992 
993 void
995 {
996  NS_LOG_FUNCTION (node);
997 
998  Ptr<RipConfig> rip_conf = node->GetObject<RipConfig> ();
999 
1000  // config generation
1001  std::stringstream conf_dir, conf_file;
1002  // FIXME XXX
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);
1011 
1012  conf_file << conf_dir.str () << "/ripd.conf";
1013  rip_conf->SetFilename ("/usr/local/etc/ripd.conf");
1014 
1015  std::ofstream conf;
1016  conf.open (conf_file.str ().c_str ());
1017  rip_conf->Print (conf);
1018  conf.close ();
1019 }
1020 
1021 void
1023 {
1024  NS_LOG_FUNCTION (node);
1025 
1026  Ptr<RipngConfig> ripng_conf = node->GetObject<RipngConfig> ();
1027 
1028  // config generation
1029  std::stringstream conf_dir, conf_file;
1030  // FIXME XXX
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);
1039 
1040  conf_file << conf_dir.str () << "/ripngd.conf";
1041  ripng_conf->SetFilename ("/usr/local/etc/ripngd.conf");
1042 
1043  std::ofstream conf;
1044  conf.open (conf_file.str ().c_str ());
1045  ripng_conf->Print (conf);
1046  conf.close ();
1047 }
1048 
1049 ApplicationContainer
1050 QuaggaHelper::Install (Ptr<Node> node)
1051 {
1052  return ApplicationContainer (InstallPriv (node));
1053 }
1054 
1055 ApplicationContainer
1056 QuaggaHelper::Install (std::string nodeName)
1057 {
1058  Ptr<Node> node = Names::Find<Node> (nodeName);
1059  return ApplicationContainer (InstallPriv (node));
1060 }
1061 
1062 ApplicationContainer
1063 QuaggaHelper::Install (NodeContainer c)
1064 {
1065  ApplicationContainer apps;
1066  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
1067  {
1068  apps.Add (InstallPriv (*i));
1069  }
1070 
1071  return apps;
1072 }
1073 
1074 ApplicationContainer
1076 {
1077  DceApplicationHelper process;
1078  ApplicationContainer apps;
1079 
1080  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig> ();
1081  if (!zebra_conf)
1082  {
1083  zebra_conf = new QuaggaConfig ();
1084  node->AggregateObject (zebra_conf);
1085  }
1086  GenerateConfigZebra (node);
1087  process.SetBinary ("zebra");
1088  process.AddArguments ("-f", zebra_conf->GetFilename ());
1089  process.AddArguments ("-i", "/usr/local/etc/zebra.pid");
1090  process.SetStackSize (1 << 16);
1091  apps.Add (process.Install (node));
1092  apps.Get (0)->SetStartTime (Seconds (1.0 + 0.01 * node->GetId ()));
1093  node->AddApplication (apps.Get (0));
1094 
1095  Ptr<OspfConfig> ospf_conf = node->GetObject<OspfConfig> ();
1096  // OSPF
1097  if (ospf_conf)
1098  {
1099  GenerateConfigOspf (node);
1100  process.ResetArguments ();
1101 
1102  process.SetBinary ("ospfd");
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));
1108  }
1109 
1110  Ptr<BgpConfig> bgp_conf = node->GetObject<BgpConfig> ();
1111  // BGP
1112  if (bgp_conf)
1113  {
1114  GenerateConfigBgp (node);
1115  process.ResetArguments ();
1116  process.SetBinary ("bgpd");
1117  process.AddArguments ("-f", bgp_conf->GetFilename ());
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 ()));
1121  // apps.Get(0)->SetStartTime (Seconds (1.2 + 0.1 * node->GetId ()));
1122  node->AddApplication (apps.Get (0));
1123  }
1124 
1125  Ptr<Ospf6Config> ospf6_conf = node->GetObject<Ospf6Config> ();
1126  // OSPF6
1127  if (ospf6_conf)
1128  {
1129  GenerateConfigOspf6 (node);
1130  process.ResetArguments ();
1131  process.SetBinary ("ospf6d");
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));
1137  }
1138 
1139  Ptr<RipConfig> rip_conf = node->GetObject<RipConfig> ();
1140  // RIP
1141  if (rip_conf)
1142  {
1143  GenerateConfigRip (node);
1144  process.ResetArguments ();
1145  process.SetBinary ("ripd");
1146  process.AddArguments ("-f", rip_conf->GetFilename ());
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));
1151  }
1152 
1153  Ptr<RipngConfig> ripng_conf = node->GetObject<RipngConfig> ();
1154  // RIPNG
1155  if (ripng_conf)
1156  {
1157  GenerateConfigRipng (node);
1158  process.ResetArguments ();
1159  process.SetBinary ("ripngd");
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));
1165  }
1166 
1167  return apps;
1168 }
1169 
1170 } // namespace ns3