Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 University of California, Los Angeles |
| 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * : Saran Tarnoi <saran.tarnoi@gmail.com> |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 22 | #include "ndn-link-control-helper.hpp" |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 23 | |
| 24 | #include "ns3/assert.h" |
| 25 | #include "ns3/names.h" |
| 26 | #include "ns3/point-to-point-net-device.h" |
| 27 | #include "ns3/point-to-point-channel.h" |
| 28 | #include "ns3/channel.h" |
| 29 | #include "ns3/log.h" |
| 30 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 31 | #include "ns3/ndn-l3-protocol.hpp" |
| 32 | #include "ns3/ndn-net-device-face.hpp" |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 34 | NS_LOG_COMPONENT_DEFINE("ndn.LinkControlHelper"); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 35 | |
| 36 | namespace ns3 { |
| 37 | namespace ndn { |
| 38 | |
| 39 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | LinkControlHelper::FailLink(Ptr<Node> node1, Ptr<Node> node2) |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 41 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 42 | NS_LOG_FUNCTION(node1 << node2); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 44 | NS_ASSERT(node1 != 0); |
| 45 | NS_ASSERT(node2 != 0); |
| 46 | |
| 47 | Ptr<ndn::L3Protocol> ndn1 = node1->GetObject<ndn::L3Protocol>(); |
| 48 | Ptr<ndn::L3Protocol> ndn2 = node2->GetObject<ndn::L3Protocol>(); |
| 49 | |
| 50 | NS_ASSERT(ndn1 != 0); |
| 51 | NS_ASSERT(ndn2 != 0); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 52 | |
| 53 | // iterate over all faces to find the right one |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | for (uint32_t faceId = 0; faceId < ndn1->GetNFaces(); faceId++) { |
| 55 | Ptr<ndn::NetDeviceFace> ndFace = ndn1->GetFace(faceId)->GetObject<ndn::NetDeviceFace>(); |
| 56 | if (ndFace == 0) |
| 57 | continue; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | Ptr<PointToPointNetDevice> nd1 = ndFace->GetNetDevice()->GetObject<PointToPointNetDevice>(); |
| 60 | if (nd1 == 0) |
| 61 | continue; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 63 | Ptr<Channel> channel = nd1->GetChannel(); |
| 64 | if (channel == 0) |
| 65 | continue; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | Ptr<PointToPointChannel> ppChannel = DynamicCast<PointToPointChannel>(channel); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | Ptr<NetDevice> nd2 = ppChannel->GetDevice(0); |
| 70 | if (nd2->GetNode() == node1) |
| 71 | nd2 = ppChannel->GetDevice(1); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 72 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | if (nd2->GetNode() == node2) { |
| 74 | Ptr<ndn::Face> face1 = ndn1->GetFaceByNetDevice(nd1); |
| 75 | Ptr<ndn::Face> face2 = ndn2->GetFaceByNetDevice(nd2); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | face1->SetUp(false); |
| 78 | face2->SetUp(false); |
| 79 | break; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 80 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | } |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 82 | } |
| 83 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | LinkControlHelper::FailLinkByName(const std::string& node1, const std::string& node2) |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 85 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | FailLink(Names::Find<Node>(node1), Names::Find<Node>(node2)); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | LinkControlHelper::UpLink(Ptr<Node> node1, Ptr<Node> node2) |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 91 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | NS_LOG_FUNCTION(node1 << node2); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 94 | NS_ASSERT(node1 != 0); |
| 95 | NS_ASSERT(node2 != 0); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 97 | Ptr<ndn::L3Protocol> ndn1 = node1->GetObject<ndn::L3Protocol>(); |
| 98 | Ptr<ndn::L3Protocol> ndn2 = node2->GetObject<ndn::L3Protocol>(); |
| 99 | |
| 100 | NS_ASSERT(ndn1 != 0); |
| 101 | NS_ASSERT(ndn2 != 0); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 102 | |
| 103 | // iterate over all faces to find the right one |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | for (uint32_t faceId = 0; faceId < ndn1->GetNFaces(); faceId++) { |
| 105 | Ptr<ndn::NetDeviceFace> ndFace = ndn1->GetFace(faceId)->GetObject<ndn::NetDeviceFace>(); |
| 106 | if (ndFace == 0) |
| 107 | continue; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 108 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 109 | Ptr<PointToPointNetDevice> nd1 = ndFace->GetNetDevice()->GetObject<PointToPointNetDevice>(); |
| 110 | if (nd1 == 0) |
| 111 | continue; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 112 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 113 | Ptr<Channel> channel = nd1->GetChannel(); |
| 114 | if (channel == 0) |
| 115 | continue; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 116 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 117 | Ptr<PointToPointChannel> ppChannel = DynamicCast<PointToPointChannel>(channel); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 118 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 119 | Ptr<NetDevice> nd2 = ppChannel->GetDevice(0); |
| 120 | if (nd2->GetNode() == node1) |
| 121 | nd2 = ppChannel->GetDevice(1); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 122 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 123 | if (nd2->GetNode() == node2) { |
| 124 | Ptr<ndn::Face> face1 = ndn1->GetFaceByNetDevice(nd1); |
| 125 | Ptr<ndn::Face> face2 = ndn2->GetFaceByNetDevice(nd2); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 126 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 127 | face1->SetUp(true); |
| 128 | face2->SetUp(true); |
| 129 | break; |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 130 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 131 | } |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 135 | LinkControlHelper::UpLinkByName(const std::string& node1, const std::string& node2) |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 136 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 137 | UpLink(Names::Find<Node>(node1), Names::Find<Node>(node2)); |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 138 | } |
Alexander Afanasyev | 0fb80b9 | 2013-07-20 08:20:50 -0700 | [diff] [blame] | 139 | } |
| 140 | } |