diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..123fa4f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,41 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose +{ + "name": "Existing Docker Compose (Extend)", + + // Update the 'dockerComposeFile' list if you have more compose files or use different names. + // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. + "dockerComposeFile": [ + "../compose.dev.yml", + "docker-compose.yml" + ], + + // The 'service' property is the name of the service for the container that VS Code should + // use. Update this value and .devcontainer/docker-compose.yml to the real service name. + "service": "sim", + + // The optional 'workspaceFolder' property is the path VS Code should open by default when + // connected. This is typically a file mount in .devcontainer/docker-compose.yml + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}" + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line if you want start specific services in your Docker Compose config. + // "runServices": [], + + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..8cf7733 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3.8' +services: + # Update this to the name of the service you want to work with in your docker-compose.yml file + sim: + # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer + # folder. Note that the path of the Dockerfile and context is relative to the *primary* + # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" + # array). The sample below assumes your primary file is in the root of your project. + # + # build: + # context: . + # dockerfile: .devcontainer/Dockerfile + + volumes: + # Update this to wherever you want VS Code to mount the folder of your project + - ..:/workspaces:cached + + # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. + # cap_add: + # - SYS_PTRACE + # security_opt: + # - seccomp:unconfined + + # Overrides default command so things don't shut down after the process ends. + command: /bin/sh -c "while sleep 1000; do :; done" + diff --git a/Dockerfile b/Dockerfile index 265cdd0..8d5b9ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ FROM ns3-base AS sim COPY ./scratch /ns3/latest/scratch COPY ./contrib /ns3/latest/contrib -ENV PATH="/ns3/latest:$PATH" +ENV PATH="/ns3/latest:$PATH" +WORKDIR /ns3/latest +RUN ./ns3 configure +RUN ./ns3 build diff --git a/Dockerfile.base b/Dockerfile.base index 1c4d024..4192a87 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -60,13 +60,13 @@ RUN mv ./ns-allinone-$VERSION/ns-$VERSION /ns3/$VERSION && ln -s /ns3/$VERSION / WORKDIR /ns3/latest # Configure -RUN ./ns3 configure -#--enable-examples --enable-tests +RUN ./ns3 configure \ +--enable-examples --enable-tests # Build RUN ./ns3 build -ENV PATH="/ns3/latest :${PATH}" +ENV PATH="/ns3/latest:${PATH}" # Test #RUN ./test.py diff --git a/compose.dev.yml b/compose.dev.yml index a35f686..6b77588 100644 --- a/compose.dev.yml +++ b/compose.dev.yml @@ -15,6 +15,8 @@ services: - ./contrib:/ns3/latest/contrib depends_on: - base + environment: + - NS_LOG=ModulatedCCA=all image: ns3-sim diff --git a/contrib/modulatedCCA b/contrib/modulatedCCA new file mode 160000 index 0000000..0b95506 --- /dev/null +++ b/contrib/modulatedCCA @@ -0,0 +1 @@ +Subproject commit 0b955062cd0bea0bd851d67423f822955c4caaa1 diff --git a/scratch/modulated-cca.cc b/scratch/modulated-cca.cc new file mode 100644 index 0000000..9ff4e15 --- /dev/null +++ b/scratch/modulated-cca.cc @@ -0,0 +1,69 @@ +#include "ns3/modulatedCCA-helper.h" +#include "ns3/applications-module.h" +#include "ns3/core-module.h" +#include "ns3/internet-module.h" +#include "ns3/network-module.h" +#include "ns3/point-to-point-module.h" +#include "ns3/log.h" + +/** + * \file + * + * Explain here what the example does. + */ + +using namespace ns3; +NS_LOG_COMPONENT_DEFINE("ModulatedCCAExample"); +int +main(int argc, char* argv[]) +{ + bool verbose = true; + + CommandLine cmd(__FILE__); + cmd.AddValue("verbose", "Tell application to log if true", verbose); + + cmd.Parse(argc, argv); + + // Setup two nodes + NodeContainer nodes; + nodes.Create(2); + + PointToPointHelper pointToPoint; + pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps")); + pointToPoint.SetChannelAttribute("Delay", StringValue("2ms")); + + NetDeviceContainer devices; + devices = pointToPoint.Install(nodes); + + InternetStackHelper stack; + stack.Install(nodes); + + Ipv4AddressHelper address; + address.SetBase("10.1.1.0", "255.255.255.0"); + + Ipv4InterfaceContainer interfaces = address.Assign(devices); + + Ipv4Address serverAddress = interfaces.GetAddress(1); + + // Create ModulatedCCA + ModulatedCCAHelper modulatedCCA(serverAddress); + + ApplicationContainer app = modulatedCCA.Install(nodes.Get(0)); + ModulatedCCA::ModulationConfig config = {ModulatedCCA::ModulationType::SIN, 1.0, 1.0, DataRate("1kbps")}; + + app.Get(0) -> SetAttribute("Name", StringValue("CCA_1")); + Ptr app1 = DynamicCast(app.Get(0)); + app1 -> SetConfig(config); + DataRate rateA = DataRate("100Mbps"); + DataRate rateB = DataRate("1000Mbps"); + DataRate rateC = rateA - rateB; + app.Start(Seconds(1.0)); + app.Stop(Seconds(10.0)); + + NS_LOG_INFO("Run Simulation."); + Simulator::Run(); + NS_LOG_UNCOND("Done."); + NS_LOG_UNCOND("Total Tx: " << DynamicCast(app.Get(0))->GetTotalTx() << " bytes."); + Simulator::Destroy(); + return 0; +} diff --git a/scratch/subdir/scratch-subdir-additional-header.cc b/scratch/subdir/scratch-subdir-additional-header.cc deleted file mode 100644 index 69efcd4..0000000 --- a/scratch/subdir/scratch-subdir-additional-header.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -// This file contains the implementation of the functions declared in the -// corresponding header file. - -#include "scratch-subdir-additional-header.h" - -namespace ns3 -{ - -std::string -ScratchSubdirGetMessage() -{ - return "Scratch Subdir"; -} - -} // namespace ns3 diff --git a/scratch/subdir/scratch-subdir-additional-header.h b/scratch/subdir/scratch-subdir-additional-header.h deleted file mode 100644 index c6a7c89..0000000 --- a/scratch/subdir/scratch-subdir-additional-header.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -// This header does not provide much functionality but is meant to demonstrate how, -// in a scratch subdirectory, one can create new programs that are implemented -// in multiple files and headers. - -#include - -namespace ns3 -{ - -/** - * Get a message from the subdir. - * - * \return The message from the subdir - */ -std::string ScratchSubdirGetMessage(); - -} // namespace ns3 diff --git a/scratch/subdir/scratch-subdir.cc b/scratch/subdir/scratch-subdir.cc deleted file mode 100644 index 23373d0..0000000 --- a/scratch/subdir/scratch-subdir.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -// This example shows how to create new simulations that are implemented in -// multiple files and headers. The structure of this simulation project -// is as follows: -// -// scratch/ -// | subdir/ -// | | - scratch-subdir.cc // Main simulation file -// | | - scratch-subdir-additional-header.h // Additional header -// | | - scratch-subdir-additional-header.cc // Additional header implementation -// -// This file contains the main() function, which calls an external function -// defined in the "scratch-subdir-additional-header.h" header file and -// implemented in "scratch-subdir-additional-header.cc". - -#include "scratch-subdir-additional-header.h" - -#include "ns3/core-module.h" - -#include - -using namespace ns3; - -NS_LOG_COMPONENT_DEFINE("ScratchSubdir"); - -int -main(int argc, char* argv[]) -{ - std::string message = ScratchSubdirGetMessage(); - NS_LOG_UNCOND(message); - - Simulator::Run(); - Simulator::Destroy(); - - return 0; -}