Skip to content

ReinhardMartin/dncs-lab

 
 

Repository files navigation

DNCS-LAB

This repository contains the Vagrant files required to run the virtual lab environment used in the DNCS course.



        +-----------------------------------------------------+
        |                                                     |
        |                                                     |eth0
        +--+--+                +------------+             +------------+
        |     |                |            |             |            |
        |     |            eth0|            |eth2     eth2|            |
        |     +----------------+  router-1  +-------------+  router-2  |
        |     |                |            |             |            |
        |     |                |            |             |            |
        |  M  |                +------------+             +------------+
        |  A  |                      |eth1                       |eth1
        |  N  |                      |                           |
        |  A  |                      |                           |
        |  G  |                      |                     +-----+----+
        |  E  |                      |eth1                 |          |
        |  M  |            +-------------------+           |          |
        |  E  |        eth0|                   |           |  host-c  |
        |  N  +------------+      SWITCH       |           |          |
        |  T  |            |                   |           |          |
        |     |            +-------------------+           +----------+
        |  V  |               |eth2         |eth3                |eth0
        |  A  |               |             |                    |
        |  G  |               |             |                    |
        |  R  |               |eth1         |eth1                |
        |  A  |        +----------+     +----------+             |
        |  N  |        |          |     |          |             |
        |  T  |    eth0|          |     |          |             |
        |     +--------+  host-a  |     |  host-b  |             |
        |     |        |          |     |          |             |
        |     |        |          |     |          |             |
        ++-+--+        +----------+     +----------+             |
        | |                              |eth0                   |
        | |                              |                       |
        | +------------------------------+                       |
        |                                                        |
        |                                                        |
        +--------------------------------------------------------+



Requirements

How-to

  • Install Virtualbox and Vagrant
  • Clone this repository git clone https://github.com/fabrizio-granelli/dncs-lab
  • You should be able to launch the lab from within the cloned repo folder.
cd dncs-lab
[~/dncs-lab] vagrant up

Once you launch the vagrant script, it may take a while for the entire topology to become available.

  • Verify the status of the 4 VMs
[dncs-lab]$ vagrant status                                                                                                                                                                
Current machine states:

router                    running (virtualbox)
switch                    running (virtualbox)
host-a                    running (virtualbox)
host-b                    running (virtualbox)
  • Once all the VMs are running verify you can log into all of them: vagrant ssh router vagrant ssh switch vagrant ssh host-a vagrant ssh host-b vagrant ssh host-c

Assignment

This section describes the assignment, its requirements and the tasks the student has to complete. The assignment consists in a simple piece of design work that students have to carry out to satisfy the requirements described below. The assignment deliverable consists of a Github repository containing:

  • the code necessary for the infrastructure to be replicated and instantiated
  • an updated README.md file where design decisions and experimental results are illustrated
  • an updated answers.yml file containing the details of your project

Design Requirements

  • Hosts 1-a and 1-b are in two subnets (Hosts-A and Hosts-B) that must be able to scale up to respectively 315 and 214 usable addresses
  • Host 2-c is in a subnet (Hub) that needs to accommodate up to 344 usable addresses
  • Host 2-c must run a docker image (dustnic82/nginx-test) which implements a web-server that must be reachable from Host-1-a and Host-1-b
  • No dynamic routing can be used
  • Routes must be as generic as possible
  • The lab setup must be portable and executed just by launching the vagrant up command

Tasks

  • Fork the Github repository: https://github.com/fabrizio-granelli/dncs-lab
  • Clone the repository
  • Run the initiator script (dncs-init). The script generates a custom answers.yml file and updates the Readme.md file with specific details automatically generated by the script itself. This can be done just once in case the work is being carried out by a group of (<=2) engineers, using the name of the 'squad lead'.
  • Implement the design by integrating the necessary commands into the VM startup scripts (create more if necessary)
  • Modify the Vagrantfile (if necessary)
  • Document the design by expanding this readme file
  • Fill the answers.yml file where required (make sure that is committed and pushed to your repository)
  • Commit the changes and push to your own repository
  • Notify the examiner (fabrizio.granelli@unitn.it) that work is complete specifying the Github repository, First Name, Last Name and Matriculation number. This needs to happen at least 7 days prior an exam registration date.

Notes and References

Design

Network requirements

  • 315 usable adresses for host-A
  • 214 usable adresses for host-B
  • 344 usable adresses for host-C
  • host-C must run a Docker image reachable by host-A and host-B
  • use only static routes as generic as possible

Addressing

There are 4 different subnets:

  1. between router-1 and router-2

require only 2 ip addresses, we use the subnet 10.1.1.0/30

NETWORK INTERFACE DEVICE IP ADDRESS
enp0s9 router-1 10.1.1.1/30
enp0s9 router-2 10.1.1.2/30
  1. between router-1 and host-a

need to manage 315 ip addresses, we use the subnet 192.168.2.0/23

NETWORK INTERFACE DEVICE IP ADDRESS
enp0s8.2 router-1 192.168.2.1/23
enp0s8 host-a 192.168.2.2/23

and create a VLAN with tag "2"

  1. between router-1 and host-b

need to manage 214 ip addresses, we use the subnet 192.168.1.0/24

NETWORK INTERFACE DEVICE IP ADDRESS
enp0s8.3 router-1 192.168.1.1/24
enp0s8 host-b 192.168.1.2/24

and create a VLAN with tag "3"

  1. between router-2 and host-c

need to manage 344 ip addresses, we use the subnet 192.168.4.0/23

NETWORK INTERFACE DEVICE IP ADDRESS
enp0s8 router-2 192.168.4.1/23
enp0s8 host-c 192.168.4.2/23

Network topology

topology

Devices configuration

The commands used to configure the network are listed and explained below:

  • assign an IP address to a specifc interface

      sudo ip addr add [ip] dev [interface]
    
  • set the interface in the "up" status

      sudo ip link set dev [interface] up
    
  • enable IPv4 forwarding

      sudo sysctl -w net.ipv4.ip_forward=1
    
  • redirect the traffic from a subnet to an IP address

      sudo ip route add [subnets addresses] via [ip] 
    
  • create a VLAN and assign a tag

      sudo ip link add link [interface] name [VLAN] type vlan id [tag]
    
  • create a bridge and assign the VLAN tag to the interfaces

      ovs-vsctl add-br switch
      ovs-vsctl add-port switch [interface]
      ovs-vsctl add-port switch [interface] tag="[tag]"
    
  • install docker and test docker image and run them

      apt update
      apt -y install docker.io
      systemctl start docker
      systemctl enable docker
      docker pull dustnic82/nginx-test
      docker run -p 80:80 -d dustnic82/nginx-test
    

Vagrant file

The Vagrant file must be modified in order to run the devices we implemented by specifying the path to the relative shell script. In addition the host-c memory must be increased from 256 MB to 512 MB because it has to run a Docker image (dustnic82/nginx-test).

    config.vm.define "host-c" do |hostc|
    hostc.vm.box = "ubuntu/bionic64"
    hostc.vm.hostname = "host-c"
    hostc.vm.network "private_network", virtualbox__intnet: "broadcast_router-south-2", auto_config: false
    hostc.vm.provision "shell", path: "host-c.sh"
    hostc.vm.provider "virtualbox" do |vb|
    vb.memory = 512
    end  

Test result

First we create the network with the command 'vagrant up', then we can log in each VM via 'vagrant ssh [VM-name]' and check the reachability of the other VMs with command 'ping -c3 [url]'. By logging in either host-a or host-b and making a request to host-c with the command 'curl 192.168.4.2' we receive the following HTML file:

<!DOCTYPE html>
<html>
<head>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ncY4rRrYYgtcCtGHPUgmjEhPmiKXjXc/l4g6HfGJT3ziEw/If86JzB/YMku9AAAAAElFTkSuQmCC" rel="icon" type="image/png" />
<style>
body {
  margin: 0px;
  font: 20px 'RobotoRegular', Arial, sans-serif;
  font-weight: 100;
  height: 100%;
  color: #0f1419;
}
div.info {
  display: table;
  background: #e8eaec;
  padding: 20px 20px 20px 20px;
  border: 1px dashed black;
  border-radius: 10px;
  margin: 0px auto auto auto;
}
div.info p {
    display: table-row;
    margin: 5px auto auto auto;
}
div.info p span {
    display: table-cell;
    padding: 10px;
}
img {
    width: 176px;
    margin: 36px auto 36px auto;
    display:block;
}
div.smaller p span {
    color: #3D5266;
}
h1, h2 {
  font-weight: 100;
}
div.check {
    padding: 0px 0px 0px 0px;
    display: table;
    margin: 36px auto auto auto;
    font: 12px 'RobotoRegular', Arial, sans-serif;
}
#footer {
    position: fixed;
    bottom: 36px;
    width: 100%;
}
#center {
    width: 400px;
    margin: 0 auto;
    font: 12px Courier;
}

</style>
<script>
var ref;
function checkRefresh(){
    if (document.cookie == "refresh=1") {
        document.getElementById("check").checked = true;
        ref = setTimeout(function(){location.reload();}, 1000);
    } else {
    }
}
function changeCookie() {
    if (document.getElementById("check").checked) {
        document.cookie = "refresh=1";
        ref = setTimeout(function(){location.reload();}, 1000);
    } else {
        document.cookie = "refresh=0";
        clearTimeout(ref);
    }
}
</script>
</head>
<body onload="checkRefresh();">
<img alt="NGINX Logo" src="http://d37h62yn5lrxxl.cloudfront.net/assets/nginx.png"/>
<div class="info">
<p><span>Server&nbsp;address:</span> <span>172.17.0.2:80</span></p>
<p><span>Server&nbsp;name:</span> <span>091638f13cf8</span></p>
<p class="smaller"><span>Date:</span> <span>11/Oct/2021:15:32:20 +0000</span></p>
<p class="smaller"><span>URI:</span> <span>/</span></p>
</div>
<br>
<div class="info">
    <p class="smaller"><span>Host:</span> <span>192.168.4.2</span></p>
    <p class="smaller"><span>X-Forwarded-For:</span> <span></span></p>
</div>

<div class="check"><input type="checkbox" id="check" onchange="changeCookie()"> Auto Refresh</div>
    <div id="footer">
        <div id="center" align="center">
            Request ID: f9dc151802ca3a764aab8628cd66f081<br/>
            &copy; NGINX, Inc. 2018
        </div>
    </div>
</body>
</html>

And here's the rendering:

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Shell 60.6%
  • Python 39.4%