1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011-2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Jaume Nin <jnin@cttc.es>
19  *         Nicola Baldo <nbaldo@cttc.es>
20  *         Manuel Requena <manuel.requena@cttc.es>
21  *         (most of the code refactored to no-backhaul-epc-helper.cc)
22  */
23 
24 #include "ns3/boolean.h"
25 #include "ns3/string.h"
26 #include "ns3/log.h"
27 #include "ns3/point-to-point-helper.h"
28 
29 #include "ns3/point-to-point-epc-helper.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("PointToPointEpcHelper");
34 
35 NS_OBJECT_ENSURE_REGISTERED (PointToPointEpcHelper);
36 
37 
PointToPointEpcHelper()38 PointToPointEpcHelper::PointToPointEpcHelper ()
39   : NoBackhaulEpcHelper ()
40 {
41   NS_LOG_FUNCTION (this);
42   // To access the attribute value within the constructor
43   ObjectBase::ConstructSelf (AttributeConstructionList ());
44 
45   // since we use point-to-point links for the backhaul links,
46   // we use a /30 subnet which can hold exactly two addresses
47   // (remember that net broadcast and null address are not valid)
48   m_s1uIpv4AddressHelper.SetBase ("10.0.0.0", "255.255.255.252");
49   m_s1apIpv4AddressHelper.SetBase ("11.0.0.0", "255.255.255.252");
50 }
51 
~PointToPointEpcHelper()52 PointToPointEpcHelper::~PointToPointEpcHelper ()
53 {
54   NS_LOG_FUNCTION (this);
55 }
56 
57 TypeId
GetTypeId(void)58 PointToPointEpcHelper::GetTypeId (void)
59 {
60   NS_LOG_FUNCTION_NOARGS ();
61   static TypeId tid = TypeId ("ns3::PointToPointEpcHelper")
62     .SetParent<NoBackhaulEpcHelper> ()
63     .SetGroupName ("Lte")
64     .AddConstructor<PointToPointEpcHelper> ()
65     .AddAttribute ("S1uLinkDataRate",
66                    "The data rate to be used for the next S1-U link to be created",
67                    DataRateValue (DataRate ("10Gb/s")),
68                    MakeDataRateAccessor (&PointToPointEpcHelper::m_s1uLinkDataRate),
69                    MakeDataRateChecker ())
70     .AddAttribute ("S1uLinkDelay",
71                    "The delay to be used for the next S1-U link to be created",
72                    TimeValue (Seconds (0)),
73                    MakeTimeAccessor (&PointToPointEpcHelper::m_s1uLinkDelay),
74                    MakeTimeChecker ())
75     .AddAttribute ("S1uLinkMtu",
76                    "The MTU of the next S1-U link to be created. Note that, because of the additional GTP/UDP/IP tunneling overhead, you need a MTU larger than the end-to-end MTU that you want to support.",
77                    UintegerValue (2000),
78                    MakeUintegerAccessor (&PointToPointEpcHelper::m_s1uLinkMtu),
79                    MakeUintegerChecker<uint16_t> ())
80     .AddAttribute ("S1uLinkPcapPrefix",
81                    "Prefix for Pcap generated by S1-U link",
82                    StringValue ("s1u"),
83                    MakeStringAccessor (&PointToPointEpcHelper::m_s1uLinkPcapPrefix),
84                    MakeStringChecker ())
85     .AddAttribute ("S1uLinkEnablePcap",
86                    "Enable Pcap for X2 link",
87                    BooleanValue (false),
88                    MakeBooleanAccessor (&PointToPointEpcHelper::m_s1uLinkEnablePcap),
89                    MakeBooleanChecker ())
90   ;
91   return tid;
92 }
93 
94 TypeId
GetInstanceTypeId() const95 PointToPointEpcHelper::GetInstanceTypeId () const
96 {
97   return GetTypeId ();
98 }
99 
100 void
DoDispose()101 PointToPointEpcHelper::DoDispose ()
102 {
103   NS_LOG_FUNCTION (this);
104   NoBackhaulEpcHelper::DoDispose ();
105 }
106 
107 
108 void
AddEnb(Ptr<Node> enb,Ptr<NetDevice> lteEnbNetDevice,uint16_t cellId)109 PointToPointEpcHelper::AddEnb (Ptr<Node> enb, Ptr<NetDevice> lteEnbNetDevice, uint16_t cellId)
110 {
111   NS_LOG_FUNCTION (this << enb << lteEnbNetDevice << cellId);
112 
113   NoBackhaulEpcHelper::AddEnb (enb, lteEnbNetDevice, cellId);
114 
115   // create a point to point link between the eNB and the SGW with
116   // the corresponding new NetDevices on each side
117   Ptr<Node> sgw = GetSgwNode ();
118 
119   PointToPointHelper p2ph;
120   p2ph.SetDeviceAttribute ("DataRate", DataRateValue (m_s1uLinkDataRate));
121   p2ph.SetDeviceAttribute ("Mtu", UintegerValue (m_s1uLinkMtu));
122   p2ph.SetChannelAttribute ("Delay", TimeValue (m_s1uLinkDelay));
123   NetDeviceContainer enbSgwDevices = p2ph.Install (enb, sgw);
124   NS_LOG_LOGIC ("Ipv4 ifaces of the eNB after installing p2p dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
125 
126   if (m_s1uLinkEnablePcap)
127     {
128       p2ph.EnablePcapAll (m_s1uLinkPcapPrefix);
129     }
130 
131   m_s1uIpv4AddressHelper.NewNetwork ();
132   Ipv4InterfaceContainer enbSgwIpIfaces = m_s1uIpv4AddressHelper.Assign (enbSgwDevices);
133   NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after assigning Ipv4 addr to S1 dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
134 
135   Ipv4Address enbS1uAddress = enbSgwIpIfaces.GetAddress (0);
136   Ipv4Address sgwS1uAddress = enbSgwIpIfaces.GetAddress (1);
137 
138   NoBackhaulEpcHelper::AddS1Interface (enb, enbS1uAddress, sgwS1uAddress, cellId);
139 }
140 
141 } // namespace ns3
142