-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgp-example_8cc-example.html
76 lines (74 loc) · 9 KB
/
bgp-example_8cc-example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>ns3-bgp: bgp-example.cc</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">ns3-bgp
 <span id="projectnumber">0.2</span>
</div>
<div id="projectbrief">BGP module for ns-3.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">bgp-example.cc</div> </div>
</div><!--header-->
<div class="contents">
<p>A simple BGP setup example with two nodes peering with each other.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include "ns3/core-module.h"</span></div><div class="line"><span class="preprocessor">#include "ns3/csma-module.h"</span></div><div class="line"><span class="preprocessor">#include "ns3/applications-module.h"</span></div><div class="line"><span class="preprocessor">#include "ns3/internet-module.h"</span></div><div class="line"><span class="preprocessor">#include "ns3/bgp.h"</span></div><div class="line"><span class="preprocessor">#include "ns3/ptr.h"</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacens3.html">ns3</a>;</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main () {</div><div class="line"> <span class="comment">// Create nodes.</span></div><div class="line"> NodeContainer n;</div><div class="line"> n.Create(2);</div><div class="line"></div><div class="line"> <span class="comment">// We need Internet stack on nodes.</span></div><div class="line"> InternetStackHelper internet;</div><div class="line"> internet.Install(n);</div><div class="line"></div><div class="line"> <span class="comment">// We need network network adapter on nodes.</span></div><div class="line"> CsmaHelper csma;</div><div class="line"> NetDeviceContainer d = csma.Install(n);</div><div class="line"></div><div class="line"> <span class="comment">// Assign IP to adapters.</span></div><div class="line"> Ipv4AddressHelper ipv4;</div><div class="line"> ipv4.SetBase(<span class="stringliteral">"10.0.0.0"</span>, <span class="stringliteral">"255.255.255.0"</span>);</div><div class="line"> Ipv4InterfaceContainer i = ipv4.Assign(d);</div><div class="line"></div><div class="line"> <span class="comment">// create applications</span></div><div class="line"> Ptr<Bgp> bgp_app_1 = CreateObject<Bgp>();</div><div class="line"> bgp_app_1->SetAttribute(<span class="stringliteral">"RouterID"</span>, Ipv4AddressValue(i.GetAddress(0)));</div><div class="line"> <span class="comment">// make libbgp verbose.</span></div><div class="line"> bgp_app_1->SetAttribute(<span class="stringliteral">"LibbgpLogLevel"</span>, EnumValue(libbgp::DEBUG)); </div><div class="line"></div><div class="line"> <span class="comment">// create peer for app1</span></div><div class="line"> <a name="_a0"></a><a class="code" href="classns3_1_1Peer.html">Peer</a> bgp_app_1_peer;</div><div class="line"> bgp_app_1_peer.<a name="a1"></a><a class="code" href="classns3_1_1Peer.html#a225668ca42e311bb083b67c1c674181c">peer_address</a> = i.GetAddress(1);</div><div class="line"> bgp_app_1_peer.<a name="a2"></a><a class="code" href="classns3_1_1Peer.html#ada8f75b39afdab49ba6cd29b54e903e3">peer_asn</a> = 65001;</div><div class="line"> bgp_app_1_peer.<a name="a3"></a><a class="code" href="classns3_1_1Peer.html#a70d5a26040c13f1f869eed00a25f4c0f">local_asn</a> = 65000;</div><div class="line"> bgp_app_1_peer.<a name="a4"></a><a class="code" href="classns3_1_1Peer.html#a477ad64dea110fa50d7e1445297b6347">passive</a> = <span class="keyword">false</span>;</div><div class="line"></div><div class="line"> <span class="comment">// add the peer config to app1.</span></div><div class="line"> bgp_app_1->AddPeer(bgp_app_1_peer);</div><div class="line"></div><div class="line"> <span class="comment">// install app1 on node0. When BGP is installed on a node, node's routing</span></div><div class="line"> <span class="comment">// protocol will be replace by a Ipv4ListRouting that contains BgpRouting</span></div><div class="line"> <span class="comment">// and Ipv4StaticRouting.</span></div><div class="line"> n.Get(0)->AddApplication(bgp_app_1);</div><div class="line"></div><div class="line"> Ptr<Bgp> bgp_app_2 = CreateObject<Bgp>();</div><div class="line"> bgp_app_2->SetAttribute(<span class="stringliteral">"RouterID"</span>, Ipv4AddressValue(i.GetAddress(1)));</div><div class="line"></div><div class="line"> <span class="comment">// add a route to node's routing table</span></div><div class="line"> bgp_app_2->AddRoute(Ipv4Address(<span class="stringliteral">"10.1.0.0"</span>), Ipv4Mask(<span class="stringliteral">"/24"</span>), i.GetAddress(1));</div><div class="line"></div><div class="line"> <span class="comment">// create peer for app2</span></div><div class="line"> <a class="code" href="classns3_1_1Peer.html">Peer</a> bgp_app_2_peer;</div><div class="line"> bgp_app_2_peer.<a class="code" href="classns3_1_1Peer.html#a225668ca42e311bb083b67c1c674181c">peer_address</a> = i.GetAddress(0);</div><div class="line"> bgp_app_2_peer.<a class="code" href="classns3_1_1Peer.html#ada8f75b39afdab49ba6cd29b54e903e3">peer_asn</a> = 65000;</div><div class="line"> bgp_app_2_peer.<a class="code" href="classns3_1_1Peer.html#a70d5a26040c13f1f869eed00a25f4c0f">local_asn</a> = 65001;</div><div class="line"> bgp_app_2_peer.<a class="code" href="classns3_1_1Peer.html#a477ad64dea110fa50d7e1445297b6347">passive</a> = <span class="keyword">false</span>;</div><div class="line"></div><div class="line"> <span class="comment">// add the peer config to app1.</span></div><div class="line"> bgp_app_2->AddPeer(bgp_app_2_peer);</div><div class="line"></div><div class="line"> <span class="comment">// install app2 on node1, When BGP is installed on a node, node's routing</span></div><div class="line"> <span class="comment">// protocol will be replace by a Ipv4ListRouting that contains BgpRouting</span></div><div class="line"> <span class="comment">// and Ipv4StaticRouting.</span></div><div class="line"> n.Get(1)->AddApplication(bgp_app_2);</div><div class="line"></div><div class="line"> <span class="comment">// set when to stop</span></div><div class="line"> bgp_app_1->SetStopTime(Seconds(100));</div><div class="line"> bgp_app_2->SetStopTime(Seconds(100));</div><div class="line"></div><div class="line"> Simulator::Run();</div><div class="line"> Simulator::Stop(Seconds(100));</div><div class="line"> Simulator::Destroy();</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>