63 } |
63 } |
64 |
64 |
65 void |
65 void |
66 PointToPointTopology::AddIpv4Addresses( |
66 PointToPointTopology::AddIpv4Addresses( |
67 Ptr<const PointToPointChannel> chan, |
67 Ptr<const PointToPointChannel> chan, |
68 Ptr<INode> n1, const Ipv4Address& addr1, |
68 Ptr<Node> n1, const Ipv4Address& addr1, |
69 Ptr<INode> n2, const Ipv4Address& addr2) |
69 Ptr<Node> n2, const Ipv4Address& addr2) |
70 { |
70 { |
71 |
71 |
72 // Duplex link is assumed to be subnetted as a /30 |
72 // Duplex link is assumed to be subnetted as a /30 |
73 // May run this unnumbered in the future? |
73 // May run this unnumbered in the future? |
74 Ipv4Mask netmask("255.255.255.252"); |
74 Ipv4Mask netmask("255.255.255.252"); |
77 // The PointToPoint channel is used to find the relevant NetDevices |
77 // The PointToPoint channel is used to find the relevant NetDevices |
78 NS_ASSERT (chan->GetNDevices () == 2); |
78 NS_ASSERT (chan->GetNDevices () == 2); |
79 Ptr<NetDevice> nd1 = chan->GetDevice (0); |
79 Ptr<NetDevice> nd1 = chan->GetDevice (0); |
80 Ptr<NetDevice> nd2 = chan->GetDevice (1); |
80 Ptr<NetDevice> nd2 = chan->GetDevice (1); |
81 // Make sure that nd1 belongs to n1 and nd2 to n2 |
81 // Make sure that nd1 belongs to n1 and nd2 to n2 |
82 if ( (nd1->GetINode ()->GetId () == n2->GetId () ) && |
82 if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && |
83 (nd2->GetINode ()->GetId () == n1->GetId () ) ) |
83 (nd2->GetNode ()->GetId () == n1->GetId () ) ) |
84 { |
84 { |
85 std::swap(nd1, nd2); |
85 std::swap(nd1, nd2); |
86 } |
86 } |
87 NS_ASSERT (nd1->GetINode ()->GetId () == n1->GetId ()); |
87 NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ()); |
88 NS_ASSERT (nd2->GetINode ()->GetId () == n2->GetId ()); |
88 NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ()); |
89 |
89 |
90 Ptr<IIpv4> ip1 = n1->QueryInterface<IIpv4> (IIpv4::iid); |
90 Ptr<IIpv4> ip1 = n1->QueryInterface<IIpv4> (IIpv4::iid); |
91 uint32_t index1 = ip1->AddInterface (nd1); |
91 uint32_t index1 = ip1->AddInterface (nd1); |
92 |
92 |
93 ip1->SetAddress (index1, addr1); |
93 ip1->SetAddress (index1, addr1); |
103 |
103 |
104 } |
104 } |
105 |
105 |
106 void |
106 void |
107 PointToPointTopology::AddIpv4Routes ( |
107 PointToPointTopology::AddIpv4Routes ( |
108 Ptr<INode> n1, Ptr<INode> n2, Ptr<const PointToPointChannel> chan) |
108 Ptr<Node> n1, Ptr<Node> n2, Ptr<const PointToPointChannel> chan) |
109 { |
109 { |
110 // The PointToPoint channel is used to find the relevant NetDevices |
110 // The PointToPoint channel is used to find the relevant NetDevices |
111 NS_ASSERT (chan->GetNDevices () == 2); |
111 NS_ASSERT (chan->GetNDevices () == 2); |
112 Ptr<NetDevice> nd1 = chan->GetDevice (0); |
112 Ptr<NetDevice> nd1 = chan->GetDevice (0); |
113 Ptr<NetDevice> nd2 = chan->GetDevice (1); |
113 Ptr<NetDevice> nd2 = chan->GetDevice (1); |
114 |
114 |
115 // Assert that n1 is the INode owning one of the two NetDevices |
115 // Assert that n1 is the Node owning one of the two NetDevices |
116 // and make sure that nd1 corresponds to it |
116 // and make sure that nd1 corresponds to it |
117 if (nd1->GetINode ()->GetId () == n1->GetId ()) |
117 if (nd1->GetNode ()->GetId () == n1->GetId ()) |
118 { |
118 { |
119 ; // Do nothing |
119 ; // Do nothing |
120 } |
120 } |
121 else if (nd2->GetINode ()->GetId () == n1->GetId ()) |
121 else if (nd2->GetNode ()->GetId () == n1->GetId ()) |
122 { |
122 { |
123 std::swap(nd1, nd2); |
123 std::swap(nd1, nd2); |
124 } |
124 } |
125 else |
125 else |
126 { |
126 { |
127 NS_FATAL_ERROR("P2PTopo: INode does not contain an interface on Channel"); |
127 NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); |
128 } |
128 } |
129 |
129 |
130 // Assert that n2 is the INode owning one of the two NetDevices |
130 // Assert that n2 is the Node owning one of the two NetDevices |
131 // and make sure that nd2 corresponds to it |
131 // and make sure that nd2 corresponds to it |
132 if (nd2->GetINode ()->GetId () != n2->GetId ()) |
132 if (nd2->GetNode ()->GetId () != n2->GetId ()) |
133 { |
133 { |
134 NS_FATAL_ERROR("P2PTopo: INode does not contain an interface on Channel"); |
134 NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); |
135 } |
135 } |
136 |
136 |
137 // Assert that both are Ipv4 nodes |
137 // Assert that both are Ipv4 nodes |
138 Ptr<IIpv4> ip1 = nd1->GetINode ()->QueryInterface<IIpv4> (IIpv4::iid); |
138 Ptr<IIpv4> ip1 = nd1->GetNode ()->QueryInterface<IIpv4> (IIpv4::iid); |
139 Ptr<IIpv4> ip2 = nd2->GetINode ()->QueryInterface<IIpv4> (IIpv4::iid); |
139 Ptr<IIpv4> ip2 = nd2->GetNode ()->QueryInterface<IIpv4> (IIpv4::iid); |
140 NS_ASSERT(ip1 != 0 && ip2 != 0); |
140 NS_ASSERT(ip1 != 0 && ip2 != 0); |
141 |
141 |
142 // Get interface indexes for both nodes corresponding to the right channel |
142 // Get interface indexes for both nodes corresponding to the right channel |
143 uint32_t index1 = 0; |
143 uint32_t index1 = 0; |
144 bool found = false; |
144 bool found = false; |