```
Verbindungen:
1. Switch Port 3-5:
IP: 10.1.1.xxx
Netzmaske: 255.255.255.0
Gateway: -
2. Router Port 2-4:
IP: 10.1.<port>.xxx
Netzmaske: 255.255.255.0
Gateway: 10.1.<port>.254
3. Router Port 5:
IP: egal
Netzmaske: 255.255.255.0 (evtl egal)
Gateway: 10.1.5.254
```
# Protokoll 2
## Konfiguration
### IP Adresse finden
Nach _Anhang B_ Interface konfigurieren.
IP-Adresse des Raspberry Pi via Wireshark ausgelesen: `192.168.137.104`
Verbindung via SSH: `$ ssh pi@192.168.137.104` erfolgreich
Interface-Name und MAC-Adresse: `$ ifconfig`:
```
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.137.105 netmask 255.255.255.0 broadcast 192.168.137.255
inet6 fe80::43c2:bf93:b7b3:36ff prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:fc:10:f5 txqueuelen 1000 (Ethernet)
RX packets 283 bytes 26177 (25.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 298 bytes 30880 (30.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
-> MAC: `b8:27:eb:fc:10:f5`
-> Interface: `eth0`
### Statische IP Adresse festlegen
`$ micro /etc/dhcpcd.conf`
```
# Example static IP configuration:
interface eth0
static ip_address=10.1.1.1/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=10.1.1.2
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
```
reboot mit `$ sudo reboot`
## Temperatursensor
Nach Schaltplan angeschlossen und Module geladen.
Richtiger Widerstand wurde mit [Digikey](https://www.digikey.de/de/resources/conversion-calculators/conversion-calculator-resistor-color-code) herausgefunden:

Schaltung:

### Einrichtung W1 Protokoll
dtoverlay nach Anleitung in boot config konfiguriert + reboot
(muss entgegen der Anleitung mit `sudo` präfix geöffnet werden)
Hinzufügen der Module in `$ sudo micro /etc/modules`
```
wire
w1-gpio
w1-therm
```
### Identifizieren des Sensors
`$ ls /sys/bus/w1/devices`
liefert
`28-01143c82f2aa w1_bus_master1` -> SensorID: 28-01143c82f2aa
Auslesen des Sensors:
`$ cat /sys/bus/w1/devices/28-01143c82f2aa/w1_slave`
liefert
```
74 01 4b 46 7f ff 0c 10 55 : crc=55 YES
74 01 4b 46 7f ff 0c 10 55 t=23250
```
-> Aktuelle Temperatur: 23.25°C
# Protokoll 3
Festlegen der lokalen IPs:
```
RaspberryPi: 10.1.1.1 Password: hwp
Switch: 10.1.1.100 Password: hwp
Moritz: 10.1.1.187
Leon: 10.1.1.120
Julien: 10.1.1.112
Janik: 10.1.1.123
```
IP Adresse von Notebook geändert zu: `192.168.88.2` und mit
`
$ ssh admin@192.168.88.1
`
mit Switch (Port 2) verbunden.
In Eingabeaufforderung Passwort zu `hwp` geändert
## Switch Konfiguration
### Switch Name
nach Rechersche mit folgendem Befehl zu `Switch-1` geändert.
`/system identity set name=Switch-1`
Wireshark Log:

### Uhrzeit
`/system clock`
Anzeige der aktuellen Einstellungen:
`print`
Editor:
`edit`
Ändern der Daten mit:
`date`, `$ timezone`, `$ time` für die jeweiligen Einstellungen
### Konfigurieren der Bridge
#### Neue Bridge erstellen
`/interface bridge`
`add` erstellt neue Bridge
`print` gibt nun die neue Bridge aus, allerdings mit falschem Namen (_bridge1_)
Ändern des Namen mit `set name=br1` und Eingabe der Bridge-Nummer `0`
```
[admin@Switch-1] /interface bridge> print
Flags: X - disabled, R - running
0 R name="br1" mtu=auto actual-mtu=1500 l2mtu=65535 arp=enabled arp-timeout=auto mac-address=76:4B:F5:1C:86:A1 protocol-mode=rstp fast-forward=yes
igmp-snooping=no auto-mac=yes ageing-time=5m priority=0x8000 max-message-age=20s forward-delay=15s transmit-hold-count=6 vlan-filtering=no
dhcp-snooping=no
```
#### Ausgabe verfügbarer Interfaces
`/interface`
`print` gibt aus:
```
Flags: D - dynamic, X - disabled, R - running, S - slave
# NAME TYPE ACTUAL-MTU L2MTU MAX-L2MTU MAC-ADDRESS
0 ether1 ether 1500 1598 2028 64:D1:54:9F:6E:38
1 R ether2 ether 1500 1598 2028 64:D1:54:9F:6E:39
2 R ether3 ether 1500 1598 2028 64:D1:54:9F:6E:3A
3 ether4 ether 1500 1598 2028 64:D1:54:9F:6E:3B
4 ether5 ether 1500 1598 2028 64:D1:54:9F:6E:3C
5 R br1 bridge 1500 65535 76:4B:F5:1C:86:A1
```
#### Hinzufügen der Interfaces zu _br1_:
`/interface bridge port`
`add bridge=br1 interface=ether<interfaceid>`
`print` gibt nun aus:
```
Flags: X - disabled, I - inactive, D - dynamic, H - hw-offload
# INTERFACE BRIDGE HW PVID PRIORITY PATH-COST INTERNAL-PATH-COST HORIZON
0 I H ether1 br1 yes 1 0x80 10 10 none
1 H ether2 br1 yes 1 0x80 10 10 none
2 H ether3 br1 yes 1 0x80 10 10 none
3 I H ether4 br1 yes 1 0x80 10 10 none
4 I H ether5 br1 yes 1 0x80 10 10 none
```
#### IP-Adresse der Bridge ändern
`/ip address add address=10.1.1.100/24 interface=br1 network=10.1.1.0`
Austesten mit verschiedenen Geräten (an unterschiedlichen Ports)
```
[admin@Switch-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 192.168.88.1/24 192.168.88.0 ether2
1 10.1.1.100/24 10.1.1.0 br1
```
#### Entfernen des Eintrages von Interface ether2
```
[admin@Switch-1] /ip address> remove number=0
[admin@Switch-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 10.1.1.100/24 10.1.1.0 br1
```
#### Verbinden von RaspberryPi mit Switch
RaspberryPi kann angepingt werden und Verbindung zu Switch und RaspberryPi mit ssh möglich (ohne Umstecken)
```
$ ping 10.1.1.1
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Antwort von 10.1.1.1: Bytes=32 Zeit=2ms TTL=64
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=64
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=64
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=64
Ping-Statistik für 10.1.1.1:
Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
(0% Verlust),
Ca. Zeitangaben in Millisek.:
Minimum = 1ms, Maximum = 2ms, Mittelwert = 1ms
```
#### MAC-Adresstabelle der Bridge br1
```
[admin@Switch-1] /interface bridge> host
[admin@Switch-1] /interface bridge host> print
Flags: X - disabled, I - invalid, D - dynamic, L - local, E - external
# MAC-ADDRESS VID ON-INTERFACE BRIDGE AGE
0 D E 50:3E:AA:D1:5B:60 ether3 br1
1 DL 64:D1:54:9F:6E:38 br1 br1
2 DL 64:D1:54:9F:6E:3A ether3 br1
3 DL 64:D1:54:9F:6E:3B ether4 br1
4 DL 64:D1:54:9F:6E:3C ether5 br1
5 D E 98:FA:9B:65:8A:B4 ether4 br1
6 D E B8:27:EB:FC:10:F5 ether5 br1
```
- Einträge #2-#4 sind die MAC-Adressen der jeweiligen Ports am Switch.
- Eintrag #6 ist die MAC-Adresse des RaspberryPi (siehe Protokoll 2).
- Auf #0 und #5 sind zwei weitere Laptops an den Switch angeschlossen.
- #1 ist der Eintrag für die Bridge selbst.
#### ARP Tabelle Notebook
```
PS C:\Users\julie> arp -a
Schnittstelle: 10.1.1.112 --- 0x7
Internetadresse Physische Adresse Typ
10.1.1.1 b8-27-eb-fc-10-f5 dynamisch
10.1.1.100 64-d1-54-9f-6e-38 dynamisch
10.1.1.255 ff-ff-ff-ff-ff-ff statisch
224.0.0.22 01-00-5e-00-00-16 statisch
224.0.0.251 01-00-5e-00-00-fb statisch
224.0.0.252 01-00-5e-00-00-fc statisch
239.255.255.250 01-00-5e-7f-ff-fa statisch
Schnittstelle: 10.107.29.152 --- 0xd
Internetadresse Physische Adresse Typ
... (WLAN Schnittstelle)
```
#### ARP Tabelle Raspberrypi
```
pi@raspberrypi:~ $ arp -e
Address HWtype HWaddress Flags Mask Iface
10.1.1.2 (unvollständig) eth0
10.1.1.123 ether 00:e0:4c:6b:5d:64 C eth0
10.1.1.112 ether 50:3e:aa:d1:5b:60 C eth0
```
#### Ping Request zu unbelegter Addresse im Subnetz
```
PS C:\Users\julie> ping 10.1.1.45
Ping wird ausgeführt für 10.1.1.45 mit 32 Bytes Daten:
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.
Ping-Statistik für 10.1.1.45:
Pakete: Gesendet = 4, Empfangen = 0, Verloren = 4
(100% Verlust),
```
Wireshark Protokoll:
`122 88.715907 TpLinkTechno_d1:5b:60 Broadcast ARP 42 Who has 10.1.1.87? Tell 10.1.1.112` (tritt mehrfach auf)
Ping an Facebook.com:

# Protokoll 4
## Einrichtung des TCP-Servers
Einrichtung des TCP-Servers wie in der Aufgabenstellung angegeben. (tcp_server.py)
Testen des TCP-Servers mit netcat:
```
pi@raspberrypi:~ $ netcat 10.1.1.112 56565
hallo
```
Antwort:
```
C:\Uni\HWP-Python\.venv\Scripts\python.exe C:\Uni\HWP\gruppe-01\section4\tcp_server.py
Connected by <socket.socket fd=460, family=2, type=1, proto=0, laddr=('0.0.0.0', 56565)> <socket.socket fd=432, family=2, type=1, proto=0, laddr=('10.1.1.112', 56565), raddr=('10.1.1.1', 53884)>
received data: b'hallo\n
```
WireShark-Mitschnitt:

## Anpassung des Skripts
Anpassung des TCP-Serverskriptes, um alle Antworten (übertragene Temperaturwerte) in einer .csv-Datei abzuspeichern:
```python=
with open(f"{datetime.now().date().strftime("%Y%m%d")}.csv", "a") as f:
f.writelines(str(int(datetime.now().timestamp())) + "," + data.decode("utf-8"))
```
## Einrichtung des TCP-Client (RaspberryPi)
Einrichtung und Anpassung des TCP-Client wie in der Aufgabenstellung angegeben. (tcp_client.py)
### Senden der Daten
```python=
try:
while True:
time.sleep(5)
temp = str(read_sensor())
print(f"Send Temp: {temp}")
s.send(bytes(temp, 'utf-8'))
finally:
s.close()
```
### Auslesen des Sensors
```python=
def read_sensor():
sensors = list([x.joinpath('w1_slave') for x in Path('/sys/bus/w1/devices').glob('28*')])
temp = 0.0
if not sensors:
print('No sensors found!')
return temp
with open(sensors[0], 'r') as fp:
data = fp.readlines()[1] # read second line
i = (len(data) - data.find('t=') - 2) * -1
temp = round(int(data[i:].replace('\n', '')) / 1000, 2)
return temp
```
### TCP Client Skript auf Raspberry speichern
Skript (tcp_client.py) wird auf RaspberryPi unter `~/tcp_client.py` gespeichert
Zum Ausführen:
```
python3 tcp_client.py
```
### Probleme bei der Ausführung
- TCP-Server muss zuerst gestartet werden
- Encoding-Error bei gesendeten Bytes in tcp_client.py ('utf-8' erforderlich; im Code oben bereits richtig angepasst):
```
C:\Uni\HWP-Python\.venv\Scripts\python.exe C:\Uni\HWP\gruppe-01\section4\tcp_client.py
Traceback (most recent call last):
File "C:\Uni\HWP\gruppe-01\section4\tcp_client.py", line 22, in <module>
s.connect((TCP_IP, TCP_PORT))
ConnectionRefusedError: [WinError 10061] Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte
Process finished with exit code 1
```
### Präsentation im Browser
#### Verwendung von plotly zur Darstellung
Für Darstellung mit plotly wird temp_http.py erstellt.
In der tcp_server.py muss die Erstellung der .csv-Dateien so geändert werden, dass immer header (timestamp, temp) eingefügt werden, um die Werte in plotly leichter verwenden zu können.
- Dropdownmenü zur Auswahl der jeweiligen .csv-datei
- temp_http.py so angepasst, dass Plot alle 5 Sekunden im Browser aktualisiert wird

#### Beobachtungen mit WireShark

- TCP-Handshakes: Ja man erkennt den Handshake an den [ACK], [SYN] und [SYN,ACK] Paketen.
- Source-Port: 62629 und 8050
- Destination-Port: 62629 und 8050
Das ausgewählte Dropdown Menü wird über das HTTP Protokoll übermittelt.

Gesamter Wireshark Verlauf Dropdown Change:

# Protokoll 5
## 5.2. Router-Einrichtung
### Grundkonfiguration
Direkte Verbidung mit Router über Port 2, setzen des Passwortes auf "hwp" für user "admin":
```shell!
PS C:\Users\User> ssh admin@192.168.88.1
The authenticity of host '192.168.88.1 (192.168.88.1)' can't be established.
RSA key fingerprint is SHA256:IVjD9sbqUzWRJj2V0/UsCOsWUXQUgOOVsRjzczO8yZU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.88.1' (RSA) to the list of known hosts.
MMM MMM KKK TTTTTTTTTTT KKK
MMMM MMMM KKK TTTTTTTTTTT KKK
MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK
MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK
MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK
MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK
MikroTik RouterOS 6.49.8 (c) 1999-2023 http://www.mikrotik.com/
[?] Gives the list of available commands
command [?] Gives help on the command and list of arguments
[Tab] Completes the command/word. If the input is ambiguous,
a second [Tab] gives possible options
/ Move up to base level
.. Move up one level
/command Use command at the base level
Change your password
new password> *** # hwp
repeat new password> ***
Password changed
```
Fehlerbehebung durch Löschen des Eintrags in der `known-hosts`-Datei:
```shell!
PS C:\Users\User> ssh admin@192.168.88.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:IVjD9sbqUzWRJj2V0/UsCOsWUXQUgOOVsRjzczO8yZU.
Please contact your system administrator.
Add correct host key in C:\\Users\\User/.ssh/known_hosts to get rid of this message.
Offending RSA key in C:\\Users\\User/.ssh/known_hosts:4
Host key for 192.168.88.1 has changed and you have requested strict checking.
Host key verification failed.
```
### Routername
```shell
[admin@MikroTik] > system identity set name="Router-1"
```
### Datum und Uhrzeit
```shell
[admin@Router-1] /system clock> set time="13:17:30"
```
### Subnetzmaskenzuweisung für Ports #1-#5 des Routers
Subnetzmaske "/24" muss immer bei Adresse mit angegeben werden.
Mittels `ip address` lassen sich die Ports konfigurieren:
```shell=
[admin@Router-1] /ip address> add
address: 10.1.1.254
interface: ether1
[admin@Router-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 192.168.88.1/24 192.168.88.0 ether2
1 10.1.1.254/32 10.1.1.254 ether1
[admin@Router-1] /ip address> remove
numbers: 1
[admin@Router-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 192.168.88.1/24 192.168.88.0 ether2
[admin@Router-1] /ip address> add
address: 10.1.1.254/24
interface: ether1
[admin@Router-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 192.168.88.1/24 192.168.88.0 ether2
1 10.1.1.254/24 10.1.1.0 ether1
[admin@Router-1] /ip address> add
address: 10.1.3.254/24
interface: ether3
[admin@Router-1] /ip address> add
address: 10.1.4.254/24
interface: ether4
[admin@Router-1] /ip address> add
address: 10.1.5.254/24
interface: ether5
[admin@Router-1] /ip address> add
address: 10.1.2.254/24
interface: ether2
[admin@Router-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 192.168.88.1/24 192.168.88.0 ether2
1 10.1.1.254/24 10.1.1.0 ether1
2 10.1.3.254/24 10.1.3.0 ether3
3 10.1.4.254/24 10.1.4.0 ether4
4 10.1.5.254/24 10.1.5.0 ether5
5 10.1.2.254/24 10.1.2.0 ether2
[admin@Router-1] /ip address>
```
### Fehler bei Verbinden mit Router
Lokale IP-Adresse muss an Subnetz angpasst sein, also z.B., wenn Laptop an Port 3 des Routers angeschlossen ist, muss lokale IP-Adresse `10.1.3.XXX` entsprechen.
Gateway am Laptop muss zu Port des Routers passen, also z.B., wenn Laptop an Port 3 des Routers, dann muss lokales Gateway z.B. `10.1.3.254`.
### Standard-Gateway des RaspberryPi
In `/etc/dhcpcd.conf` wird static `routers=10.1.1.254` geändert.
Reboot zum übernehmen.
### Fehler bei Verbinden mit RaspberryPi
Verbindung mit RaspberryPi ist nicht mehr möglich, wenn Laptop an Router angeschlossen ist.
Lösung: WLan ausschalten, da ansonsten Standard-Gateway von WLan verwendet wird.
### Löschen des alten ether2
```shell
[admin@Router-1] /ip address> remove 0
[admin@Router-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 10.1.1.254/24 10.1.1.0 ether1
1 10.1.3.254/24 10.1.3.0 ether3
2 10.1.4.254/24 10.1.4.0 ether4
3 10.1.5.254/24 10.1.5.0 ether5
4 10.1.2.254/24 10.1.2.0 ether2
[admin@Router-1] /ip address>
```
### Ping an RaspberryPi
```shell
janik@osiris:~$ ping 10.1.1.1
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=63 time=0.782 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=63 time=1.42 ms
64 bytes from 10.1.1.1: icmp_seq=3 ttl=63 time=0.699 ms
64 bytes from 10.1.1.1: icmp_seq=4 ttl=63 time=0.697 ms
64 bytes from 10.1.1.1: icmp_seq=5 ttl=63 time=0.730 ms
64 bytes from 10.1.1.1: icmp_seq=6 ttl=63 time=0.725 ms
64 bytes from 10.1.1.1: icmp_seq=7 ttl=63 time=0.743 ms
64 bytes from 10.1.1.1: icmp_seq=8 ttl=63 time=0.712 ms
64 bytes from 10.1.1.1: icmp_seq=9 ttl=63 time=0.687 ms
^C
--- 10.1.1.1 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8219ms
rtt min/avg/max/mdev = 0.687/0.799/1.422/0.221 ms
```
$\Rightarrow$ Ping war erfolgreich!
### Anlegen der statischen Route
Um nicht immer die Verbindung zu anderen Netzwerken trennen zu müssen, um z.B. den RaspberryPi anzupingen, werden statische Routen im eigenen Gerät angelegt.
(z.B.: Laptop an Port 2 des Routers $\rightarrow$ Gateway `10.1.2.254`)
Unter Windows:
```shell
PS C:\Users\User> route ADD 10.1.0.0 MASK 255.255.0.0 10.1.2.254
OK!
PS C:\Users\User> ping 10.1.1.1
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=63
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=63
Antwort von 10.1.1.1: Bytes=32 Zeit<1ms TTL=63
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=63
Ping-Statistik für 10.1.1.1:
Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
(0% Verlust),
Ca. Zeitangaben in Millisek.:
Minimum = 0ms, Maximum = 1ms, Mittelwert = 0ms
```
Unter Linux:
```shell
janik@osiris:~$ sudo ip route add 10.1.0.0/16 via 10.1.3.254 proto static metric 100
janik@osiris:~$ ping 10.1.1.1
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=63 time=87.5 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=63 time=0.681 ms
^C
--- 10.1.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.681/44.086/87.491/43.405 ms
```
## 5.3. NAT-Konfiguration
### Port #5 - öffentliches Netz
Port #5 des Routers wird mit folgendem Befehl als öffentlicher Port eingerichtet:
```shell
[admin@Router-1] /ip firewall nat> add chain="srcnat" src-address="10.1.1.0/24" action=src-nat to-address="10.1.5.254/24
" out-interface=ether5
```
### Firewall-Filter
Anmerkung: `chain` ist vordefiniert. Ermöglicht Hinzufügen von Regeln.
#### Hinzufügen der Filter Regeln
```shell
[admin@Router-1] /ip firewall filter> add chain=forward action=drop src-address=10.1.5.0/24 connection-state=new connection-nat-state=!dstnat
```
#### Ausgabe - Regel
```shell
[admin@Router-1] /ip firewall filter> print
Flags: X - disabled, I - invalid, D - dynamic
0 chain=forward action=drop connection-state=new connection-nat-state=!dstnat src-address=10.1.5.0/24
```
$\Rightarrow$ Versuch über Port #5 zu pingen schlägt nun fehl:
```shell
PS C:\Users\julie> ping 10.1.1.1
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.
Zeitüberschreitung der Anforderung.
Ping-Statistik für 10.1.1.1:
Pakete: Gesendet = 4, Empfangen = 0, Verloren = 4
(100% Verlust)
```
#### Hinzufügen der Nat Konfiguration
Folgende Regeln werden hinzugefügt:
```shell
[admin@Router-1] /ip firewall nat> print
Flags: X - disabled, I - invalid, D - dynamic
0 chain=srcnat action=src-nat to-addresses=10.1.5.254 src-address=10.1.1.0/24 out-interface=ether5
1 chain=srcnat action=src-nat to-addresses=10.1.5.254 src-address=10.1.2.0/24 out-interface=ether5
2 chain=srcnat action=src-nat to-addresses=10.1.5.254 src-address=10.1.3.0/24 out-interface=ether5
3 chain=srcnat action=src-nat to-addresses=10.1.5.254 src-address=10.1.4.0/24 out-interface=ether5
4 chain=dstnat action=dst-nat to-addresses=10.1.1.1 to-ports=22 protocol=tcp dst-address=10.1.5.254
in-interface=ether5 dst-port=10022
```
#### Zugriff auf Pi über SSH
Der Zugriff mit SSH über den Port 5 erfolgt nun folgendermaßen:
```shell
PS C:\Users\julie> ssh pi@10.1.5.254 -p 10022
pi@10.1.5.254's password:
Last login: Thu Apr 25 23:37:13 2024 from 10.1.5.112
pi@raspberrypi:~ $
```
### Ausgabe der Routen im Router
```shell
[admin@Router-1] > /ip route print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.1.1.0/24 10.1.1.254 ether1 0
1 ADC 10.1.2.0/24 10.1.2.254 ether2 0
2 DC 10.1.3.0/24 10.1.3.254 ether3 255
3 DC 10.1.4.0/24 10.1.4.254 ether4 255
4 ADC 10.1.5.0/24 10.1.5.254 ether5 0
```
## 5.4 Entfernte Subnetze und Routingprotokolle
### 5.4.1 Neuer Versuchsaufbau
#### Switch konfigurieren
Löschen von `ether1` aus `br1`
```shell
[admin@Switch-1] /interface bridge port> print
Flags: X - disabled, I - inactive, D - dynamic, H - hw-offload
# INTERFACE BRIDGE HW PVID PRIORITY PATH-COST INTERNAL-PATH-COST HORIZON
0 I H ether1 br1 yes 1 0x80 10 10 none
1 H ether2 br1 yes 1 0x80 10 10 none
2 H ether3 br1 yes 1 0x80 10 10 none
3 I H ether4 br1 yes 1 0x80 10 10 none
4 I H ether5 br1 yes 1 0x80 10 10 none
[admin@Switch-1] /interface bridge port> remove
numbers: 0
[admin@Switch-1] /interface bridge port> print
Flags: X - disabled, I - inactive, D - dynamic, H - hw-offload
# INTERFACE BRIDGE HW PVID PRIORITY PATH-COST INTERNAL-PATH-COST HORIZON
0 H ether2 br1 yes 1 0x80 10 10 none
1 H ether3 br1 yes 1 0x80 10 10 none
2 I H ether4 br1 yes 1 0x80 10 10 none
3 I H ether5
```
Hinzufügen der Adresskonfiguration:
```shell
[admin@Switch-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 10.1.1.100/24 10.1.1.0 br1
[admin@Switch-1] /ip address> add
address: 10.0.0.2/30
interface: ether1
[admin@Switch-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 10.1.1.100/24 10.1.1.0 br1
1 10.0.0.2/30 10.0.0.0 ether1
```
#### Router konfigurieren
Ändern der IP Adresse von `ether1`
```shell
[admin@Router-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 10.1.1.254/24 10.1.1.0 ether1
1 10.1.3.254/24 10.1.3.0 ether3
2 10.1.4.254/24 10.1.4.0 ether4
3 10.1.5.254/24 10.1.5.0 ether5
4 10.1.2.254/24 10.1.2.0 ether2
[admin@Router-1] /ip address> add
address: 10.0.0.1/30
interface: ether1
[admin@Router-1] /ip address> print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 10.1.1.254/24 10.1.1.0 ether1
1 10.1.3.254/24 10.1.3.0 ether3
2 10.1.4.254/24 10.1.4.0 ether4
3 10.1.5.254/24 10.1.5.0 ether5
4 10.1.2.254/24 10.1.2.0 ether2
5 10.0.0.1/30 10.0.0.0 ether1
```
Löschen der alten IP Adresse von `ether1`
```shell
[admin@Router-1] /ip address> remove
numbers: 0
[admin@Router-1] > ip address print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK INTERFACE
0 10.1.3.254/24 10.1.3.0 ether3
1 10.1.4.254/24 10.1.4.0 ether4
2 10.1.5.254/24 10.1.5.0 ether5
3 10.1.2.254/24 10.1.2.0 ether2
4 10.0.0.1/30 10.0.0.0 ether1
```
#### Ping Switch und Rasp von Router
```shell
[admin@Router-1] > ping 10.0.0.2
SEQ HOST SIZE TTL TIME STATUS
0 10.0.0.2 56 64 0ms
1 10.0.0.2 56 64 0ms
2 10.0.0.2 56 64 0ms
3 10.0.0.2 56 64 0ms
sent=4 received=4 packet-loss=0% min-rtt=0ms avg-rtt=0ms max-rtt=0ms
[admin@Router-1] > ping 10.1.1.1
SEQ HOST SIZE TTL TIME STATUS
0 no route to host
1 no route to host
2 no route to host
3 no route to host
```
### 5.4.2 Statische Routen
#### Hinzufügen der statischen Route am Router
```shell!
[admin@Router-1] /ip route> print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.1 ether1 0
1 DC 10.1.2.0/24 10.1.2.254 ether2 255
2 ADC 10.1.3.0/24 10.1.3.254 ether3 0
3 DC 10.1.4.0/24 10.1.4.254 ether4 255
4 ADC 10.1.5.0/24 10.1.5.254 ether5 0
[admin@Router-1] /ip route> add gateway=10.0.0.2 dst-address=10.1.1.0/24
[admin@Router-1] /ip route> print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.1 ether1 0
1 A S 10.1.1.0/24 10.0.0.2 1
2 DC 10.1.2.0/24 10.1.2.254 ether2 255
3 ADC 10.1.3.0/24 10.1.3.254 ether3 0
4 DC 10.1.4.0/24 10.1.4.254 ether4 255
5 ADC 10.1.5.0/24 10.1.5.254 ether5 0
```
Die neue Route hat nun den `s` Flag, der eine statische Route definiert.
#### Hinzufügen der statischen Routen am Switch
```shell
[admin@Switch-1] /ip route> add gateway=10.0.0.1 dst-address=10.1.2.0/24
[admin@Switch-1] /ip route> add gateway=10.0.0.1 dst-address=10.1.3.0/24
[admin@Switch-1] /ip route> add gateway=10.0.0.1 dst-address=10.1.4.0/24
[admin@Switch-1] /ip route> add gateway=10.0.0.1 dst-address=10.1.5.0/24
```
#### Problem
Timeout bei Ping von Router nach Raspberry Pi
```shell!
[admin@Router-1] > ping 10.1.1.1
SEQ HOST SIZE TTL TIME STATUS
0 10.1.1.1 timeout
1 10.1.1.1 timeout
2 10.1.1.1 timeout
3 10.1.1.1 timeout
4 10.1.1.1 timeout
5 10.1.1.1 timeout
6 10.1.1.1 timeout
sent=7 received=0 packet-loss=100%
```
Lösung: Gateway am Raspberry Pi falsch konfiguriert.
in `/etc/dhcpcd.conf`
```shell
static routers=10.1.1.254
zu
static routers=10.1.1.100
```
#### Abschließend ping testen
```shell
[admin@Router-1] > ping 10.1.1.1
SEQ HOST SIZE TTL TIME STATUS
0 10.1.1.1 56 63 0ms
1 10.1.1.1 56 63 0ms
2 10.1.1.1 56 63 0ms
3 10.1.1.1 56 63 0ms
sent=4 received=4 packet-loss=0% min-rtt=0ms avg-rtt=0ms max-rtt=0ms
```
### RIP
#### Löschen der zuvor erstellten statischen Routen
##### Im Switch alle mit Flag 'S'
```shell
[admin@Switch-1] /ip route> remove 2
[admin@Switch-1] /ip route> remove 3
[admin@Switch-1] /ip route> remove 4
[admin@Switch-1] /ip route> remove 5
[admin@Switch-1] /ip route> print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.2 ether1 0
1 ADC 10.1.1.0/24 10.1.1.100 br1 0
```
##### Im Router alle mit Flag 'S'
```shell
[admin@Router-1] /ip route> print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.1 ether1 0
1 A S 10.1.1.0/24 10.0.0.2 1
2 DC 10.1.2.0/24 10.1.2.254 ether2 255
3 ADC 10.1.3.0/24 10.1.3.254 ether3 0
4 ADC 10.1.4.0/24 10.1.4.254 ether4 0
5 DC 10.1.5.0/24 10.1.5.254 ether5 255
[admin@Router-1] /ip route> remove 1
[admin@Router-1] /ip route> print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.1 ether1 0
1 DC 10.1.2.0/24 10.1.2.254 ether2 255
2 ADC 10.1.3.0/24 10.1.3.254 ether3 0
3 ADC 10.1.4.0/24 10.1.4.254 ether4 0
4 DC 10.1.5.0/24 10.1.5.254 ether5 255
[admin@Router-1] /ip route>
```
##### Ping Pi von Router
```shell!
[admin@Router-1] > ping 10.1.1.1
SEQ HOST SIZE TTL TIME STATUS
0 no route to host
1 no route to host
2 no route to host
3 no route to host
4 no route to host
5 no route to host
sent=6 received=0 packet-loss=100%
```
#### Hinzufügen der Netzwerke am Router in RIP
```shell!
[admin@Router-1] /routing rip network> add network=10.0.0.0/30
[admin@Router-1] /routing rip network> print
Flags: X - disabled
# NETWORK
0 10.0.0.0/30
[admin@Router-1] /routing rip network> add network=10.1.2.0/24
[admin@Router-1] /routing rip network> add network=10.1.3.0/24
[admin@Router-1] /routing rip network> add network=10.1.4.0/24
[admin@Router-1] /routing rip network> add network=10.1.5.0/24
[admin@Router-1] /routing rip network> print
Flags: X - disabled
# NETWORK
0 10.0.0.0/30
1 10.1.2.0/24
2 10.1.3.0/24
3 10.1.4.0/24
4 10.1.5.0/24
[admin@Router-1] > /routing rip route print
Flags: C - connect, S - static, R - rip, O - ospf, B - bgp
# DST-ADDRESS GATEWAY FROM METRIC TIMEOUT
0 R 10.0.0.0/30 1
1 R 10.1.1.0/24 10.0.0.2 2 2m53s
2 R 10.1.3.0/24 1
3 R 10.1.4.0/24 1
[admin@Router-1] > /ip route print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.1 ether1 0
1 ADr 10.1.1.0/24 10.0.0.2 120
2 DC 10.1.2.0/24 10.1.2.254 ether2 255
3 ADC 10.1.3.0/24 10.1.3.254 ether3 0
4 ADC 10.1.4.0/24 10.1.4.254 ether4 0
5 DC 10.1.5.0/24 10.1.5.254 ether5 255
```
#### Hinzufügen der Netzwerke am Switch in RIP
```shell
[admin@Switch-1] /routing rip network> add network=10.0.0.0/30
[admin@Switch-1] /routing rip network> add network=10.1.1.0/24
[admin@Switch-1] /routing rip network> print
Flags: X - disabled
# NETWORK
0 10.0.0.0/30
1 10.1.1.0/24
[admin@Switch-1] /routing rip route print>
Flags: C - connect, S - static, R - rip, O - ospf, B - bgp
# DST-ADDRESS GATEWAY FROM METRIC TIMEOUT
0 R 10.0.0.0/30 1
1 R 10.1.1.0/24 1
2 R 10.1.3.0/24 10.0.0.1 2 2m36s
3 R 10.1.4.0/24 10.0.0.1 2 2m36s
[admin@Switch-1] > /ip route print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.2 ether1 0
1 ADC 10.1.1.0/24 10.1.1.100 br1 0
2 ADr 10.1.3.0/24 10.0.0.1 120
3 ADr 10.1.4.0/24 10.0.0.1 120
```
#### Ping von Laptop zu Raspi geht wieder (Laptop am Router)
```shell!
PS C:\Users\User> ping 10.1.1.1
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=62
Antwort von 10.1.1.1: Bytes=32 Zeit<1ms TTL=62
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=62
Antwort von 10.1.1.1: Bytes=32 Zeit<1ms TTL=62
Ping-Statistik für 10.1.1.1:
Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
(0% Verlust),
Ca. Zeitangaben in Millisek.:
Minimum = 0ms, Maximum = 1ms, Mittelwert = 0ms
```
#### Kurze Zwischenfragen
Achten Sie bei den Routing-Listen auf die Details: Welche Routen sind in der Liste enthalten?
Es sind alle Routen enthalten, deren Ports aktiv verwendet werden.
Welche fehlen?
Alle Routen deren Ports nicht verwendet werden. In unserem Fall aktuell Port 2 und 5.
Was bedeuten die Flags in den Listen?
Die Flags werden beim Print erklärt. A: active; C: connect; etc.
Was bedeuten die Spalten METRIC und DISTANCE?
Metric: Er bezeichnet die Anzahl der Router, die entlang eines Pfades bis zum Zielnetz durchlaufen werden müssen.
Distance: Distance beschreibt die Distanz. Bei 255 wird der Port nicht verwendet, bei 0 ist es der eigene Port. 120 ist die Standarddistanz.
### OSPF
#### Entfernen der Netzwerke aus RIP Tabelle des Routers
```shell
[admin@Router-1] > /routing rip network remove 0
[admin@Router-1] > /routing rip route print
Flags: C - connect, S - static, R - rip, O - ospf, B - bgp
# DST-ADDRESS GATEWAY FROM METRIC TIMEOUT
[admin@Router-1] > /routing rip network print
Flags: X - disabled
# NETWORK
```
#### Entfernen der Netzwerke aus RIP Tabelle des Switches
```shell
[admin@Switch-1] > /routing rip network remove 0
[admin@Switch-1] /routing rip route> print
Flags: C - connect, S - static, R - rip, O - ospf, B - bgp
# DST-ADDRESS GATEWAY FROM METRIC TIMEOUT
[admin@Switch-1] /routing rip network> print
Flags: X - disabled
# NETWORK
```
#### Prüfung ob Router Standard OSPF Instance/Area verfügbar
```shell
[admin@Router-1] /routing ospf instance> print
Flags: X - disabled, * - default
0 * name="default" router-id=0.0.0.0 distribute-default=never redistribute-connected=no redistribute-static=no
redistribute-rip=no redistribute-bgp=no redistribute-other-ospf=no metric-default=1 metric-connected=20
metric-static=20 metric-rip=20 metric-bgp=auto metric-other-ospf=auto in-filter=ospf-in out-filter=ospf-out
[admin@Router-1] /routing ospf area> print
Flags: X - disabled, I - invalid, * - default
# NAME AREA-ID TYPE DEFAULT-COST
0 * backbone 0.0.0.0 default
```
#### Prüfung ob Switch Standard OSPF Instance/Area verfügbar
```shell
[admin@Switch-1] /routing ospf instance> print
Flags: X - disabled, * - default
0 * name="default" router-id=0.0.0.0 distribute-default=never redistribute-connected=no redistribute-static=no
redistribute-rip=no redistribute-bgp=no redistribute-other-ospf=no metric-default=1 metric-connected=20
metric-static=20 metric-rip=20 metric-bgp=auto metric-other-ospf=auto in-filter=ospf-in out-filter=ospf-out
[admin@Switch-1] /routing ospf area> print
Flags: X - disabled, I - invalid, * - default
# NAME AREA-ID TYPE DEFAULT-COST
0 * backbone 0.0.0.0 default
```
#### Hinzufügen von OSPF Network beim Router
```shell
[admin@Router-1] /routing ospf network> add network=10.0.0.0/30 area=backbone
[admin@Router-1] /routing ospf network> print
Flags: X - disabled, I - invalid
# NETWORK AREA
0 10.0.0.0/30 backbone
[admin@Router-1] /routing ospf network> add network=10.1.2.0/24 area=backbone
[admin@Router-1] /routing ospf network> add network=10.1.3.0/24 area=backbone
[admin@Router-1] /routing ospf network> add network=10.1.4.0/24 area=backbone
[admin@Router-1] /routing ospf network> add network=10.1.5.0/24 area=backbone
[admin@Router-1] /routing ospf network> print
Flags: X - disabled, I - invalid
# NETWORK AREA
0 10.0.0.0/30 backbone
1 10.1.2.0/24 backbone
2 10.1.3.0/24 backbone
3 10.1.4.0/24 backbone
4 10.1.5.0/24 backbone
[admin@Router-1] /routing ospf network> /ip route print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.1 ether1 0
1 ADo 10.1.1.0/24 10.0.0.2 110
2 DC 10.1.2.0/24 10.1.2.254 ether2 255
3 ADC 10.1.3.0/24 10.1.3.254 ether3 0
4 ADC 10.1.4.0/24 10.1.4.254 ether4 0
5 DC 10.1.5.0/24 10.1.5.254 ether5 255
```
#### Hinzufügen von OSPF Network beim Switch
```shell
[admin@Switch-1] /routing ospf network> add network=10.0.0.0/30
area: backbone
[admin@Switch-1] /routing ospf network> add network=10.1.1.0/24
area: backbone
[admin@Switch-1] /routing ospf network> print
Flags: X - disabled, I - invalid
# NETWORK AREA
0 10.0.0.0/30 backbone
1 10.1.1.0/24 backbone
[admin@Switch-1] /routing ospf network> /ip route print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 10.0.0.0/30 10.0.0.2 ether1 0
1 ADC 10.1.1.0/24 10.1.1.100 br1 0
2 ADo 10.1.3.0/24 10.0.0.1 110
3 ADo 10.1.4.0/24 10.0.0.1 110
```
### Export Router
```shell!
[admin@Router-1] > export
# may/15/2024 14:26:38 by RouterOS 6.49.8
# software id = PUSP-SIE8
#
# model = RouterBOARD 750 r2
# serial number = 67D207F8A4C9
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip address
add address=10.1.3.254/24 interface=ether3 network=10.1.3.0
add address=10.1.4.254/24 interface=ether4 network=10.1.4.0
add address=10.1.5.254/24 interface=ether5 network=10.1.5.0
add address=10.1.2.254/24 interface=ether2 network=10.1.2.0
add address=10.0.0.1/30 interface=ether1 network=10.0.0.0
/ip firewall filter
add action=drop chain=forward connection-nat-state=!dstnat connection-state=new src-address=10.1.5.0/24
/ip firewall nat
add action=src-nat chain=srcnat out-interface=ether5 src-address=10.1.1.0/24 to-addresses=10.1.5.254
add action=src-nat chain=srcnat out-interface=ether5 src-address=10.1.2.0/24 to-addresses=10.1.5.254
add action=src-nat chain=srcnat out-interface=ether5 src-address=10.1.3.0/24 to-addresses=10.1.5.254
add action=src-nat chain=srcnat out-interface=ether5 src-address=10.1.4.0/24 to-addresses=10.1.5.254
add action=dst-nat chain=dstnat dst-address=10.1.5.254 dst-port=10022 in-interface=ether5 protocol=tcp to-addresses=\
10.1.1.1 to-ports=22
/routing ospf network
add area=backbone network=10.0.0.0/30
add area=backbone network=10.1.2.0/24
add area=backbone network=10.1.3.0/24
add area=backbone network=10.1.4.0/24
add area=backbone network=10.1.5.0/24
/system identity
set name=Router-1
[admin@Router-1] >
```
### Export Switch
```shell
/interface bridge
add name=br1
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/interface bridge port
add bridge=br1 interface=ether2
add bridge=br1 interface=ether3
add bridge=br1 interface=ether4
add bridge=br1 interface=ether5
/ip address
add address=10.1.1.100/24 interface=br1 network=10.1.1.0
add address=10.0.0.2/30 interface=ether1 network=10.0.0.0
/routing ospf network
add area=backbone network=10.0.0.0/30
add area=backbone network=10.1.1.0/24
/system clock
set time-zone-name=Europe/Berlin
/system identity
set name=Switch-1
```
Beim Übergang auf Section 6 wurden alle dynamisches Routing auf statische geändert.
# Protokoll 6
## 6.2 Aufnahme von Audiosignalen
### ID's
```shell
pi@raspberrypi:~ $ arecord --list-devices
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
```
$\Rightarrow$ **Geräte-ID: 0,
Karten-ID: 1**
### Test Aufnahme
```shell
pi@raspberrypi:~ $ arecord --file-type wav --format cd --device hw:1,0 --channels 1 --duration 5 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono
```
### Veränderung der Standart-Werte
Erhöhung der Sample-Rate um 50 Hz (44150), da dieser Wert nicht erlaubt ist, wird automatisch auf 48000 Hz gesetzt.
```shell
pi@raspberrypi:~ $ arecord -t wav -f S16_LE -r 44150 -V mono -D hw:1,0 -c 1 -d 5 test5.wav
```
#### Zwischenfragen
Welche Abtastrate würden Sie hierzu verwenden? 44,1 kHz.
Mit welcher Rate werden bspw. Audio-CDs kodiert? 44,1 kHz.
Was würde Ihrer Meinung nach für alleinige Sprache ausreichen? 4 kHz, da die Menschliche Sprache einen Frequenzbereich von bis zu 2 kHz hat und mit der doppelten Frequenz das ursprüngliche Signal vollständig rekonstruiert werden kann.
#### Unterschiedliche Sample-Raten
Anpassung der Raten (z.B. auf 6000Hz)
```shell
pi@raspberrypi:~ $ sox test4.wav -r 6000 -c 1 -b 16 test4_6000.wav
```
Beobachtung: Ab ~6000Hz kaum mehr merkbarer Unterschied zu 44,1kHz
## 6.3 Einlesen von Audiodateien in Python
Siehe Code in Gitlab.
Verstärkte Audiodatei anhören: Die Datei ist besser verständlich, wenn die Datei sonst zu leise ist. Sehr laute Bereiche, die noch zustätzlich verstärkt werden, sind allerdings übersteuert und somit teils nicht mehr verständlich.
## 6.4 Fouriertranformation & Bandpass
### Informationen der Diagramme
Man kann ablesen wie häufig eine Frequenz aufgetreten ist.
x-Achse: Frequenz [Hz]
y-Achse: Häufigkeit
(Code siehe GitLab)
Betrachtet man die Darstellung unterschiedlicher Töne (z.B. von Mann und Frau), lässt sich feststellen, dass bei Männern häufiger tiefe Frequenzen auftreten. Bei Frauen hingegen sind häufiger höhere Frequenzen beobachtbar.
Um die Daten im Frequenzbereich zu bearbeiten, um z.B. Stimmen klarer zu machen, kann ein Bandpassfilter (nur Frequenzen in einem bestimmten Bereich werden erhalten) verwenden.
### Bandpassfilter
Für den Bandpassfilter werden nur Frequenzen im Bereich 250-2500Hz (Frequenzen für menschliche Sprache) zugelassen.
Plots sind im GitLab:
- orig.png: Plot der Audiofile im Zeitbereich
- orig_fourier.png: Plot der Audiofile im Frequenzbereich
- filtered_fourier.png: Audiofile mit Bandpassfilter im Frequenzbereich
- filtered.png: Audiofile mit Bandpassfilter im Zeitbereich
- filtered.wav: Bearbeitete Soundfile (mit Bandpassfilter)
# Protokoll 7
## 7.3 Messung und Identifikation der Latenzprofile
### Ping verbindung vom PC zum PI ohne NetEm
```shell
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=61 time=3.21 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=61 time=2.08 ms
64 bytes from 10.1.1.1: icmp_seq=3 ttl=61 time=1.72 ms
64 bytes from 10.1.1.1: icmp_seq=4 ttl=61 time=1.65 ms
64 bytes from 10.1.1.1: icmp_seq=5 ttl=61 time=2.32 ms
64 bytes from 10.1.1.1: icmp_seq=6 ttl=61 time=1.91 ms
--- 10.1.1.1 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5026ms
rtt min/avg/max/mdev = 1.653/2.148/3.205/0.521 ms`
````
### Ping Verbindung vom PC zum Pi mit NetEm
```shell
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=61 time=38.4 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=61 time=49.1 ms
64 bytes from 10.1.1.1: icmp_seq=3 ttl=61 time=53.8 ms
64 bytes from 10.1.1.1: icmp_seq=4 ttl=61 time=42.0 ms
64 bytes from 10.1.1.1: icmp_seq=5 ttl=61 time=51.0 ms
--- 10.1.1.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4045ms
rtt min/avg/max/mdev = 38.407/46.867/53.763/5.753 ms
```
-> Wie man oben sieht hat sich die Latenz deutlich verstärkt und schwankt sehr viel
### Wie viele Profile hat das NetEm
```shell
// 1. Profile
64 bytes from 10.1.1.1: icmp_seq=2 ttl=61 time=48.0 ms
64 bytes from 10.1.1.1: icmp_seq=3 ttl=61 time=54.6 ms
64 bytes from 10.1.1.1: icmp_seq=4 ttl=61 time=54.9 ms
64 bytes from 10.1.1.1: icmp_seq=5 ttl=61 time=50.2 ms
64 bytes from 10.1.1.1: icmp_seq=6 ttl=61 time=71.1 ms
64 bytes from 10.1.1.1: icmp_seq=7 ttl=61 time=54.2 ms
64 bytes from 10.1.1.1: icmp_seq=8 ttl=61 time=50.0 ms
64 bytes from 10.1.1.1: icmp_seq=9 ttl=61 time=69.6 ms
64 bytes from 10.1.1.1: icmp_seq=10 ttl=61 time=49.9 ms
64 bytes from 10.1.1.1: icmp_seq=11 ttl=61 time=52.4 ms
64 bytes from 10.1.1.1: icmp_seq=12 ttl=61 time=73.3 ms
64 bytes from 10.1.1.1: icmp_seq=13 ttl=61 time=72.3 ms
64 bytes from 10.1.1.1: icmp_seq=14 ttl=61 time=55.3 ms
64 bytes from 10.1.1.1: icmp_seq=15 ttl=61 time=60.5 ms
64 bytes from 10.1.1.1: icmp_seq=16 ttl=61 time=44.9 ms
64 bytes from 10.1.1.1: icmp_seq=17 ttl=61 time=47.4 ms
64 bytes from 10.1.1.1: icmp_seq=18 ttl=61 time=56.7 ms
64 bytes from 10.1.1.1: icmp_seq=19 ttl=61 time=63.0 ms
64 bytes from 10.1.1.1: icmp_seq=20 ttl=61 time=41.6 ms
64 bytes from 10.1.1.1: icmp_seq=21 ttl=61 time=57.3 ms
64 bytes from 10.1.1.1: icmp_seq=22 ttl=61 time=42.0 ms
64 bytes from 10.1.1.1: icmp_seq=23 ttl=61 time=64.9 ms
64 bytes from 10.1.1.1: icmp_seq=24 ttl=61 time=41.8 ms
64 bytes from 10.1.1.1: icmp_seq=26 ttl=61 time=62.7 ms
64 bytes from 10.1.1.1: icmp_seq=27 ttl=61 time=46.5 ms
// 2. Profile
64 bytes from 10.1.1.1: icmp_seq=28 ttl=61 time=338 ms
64 bytes from 10.1.1.1: icmp_seq=29 ttl=61 time=313 ms
64 bytes from 10.1.1.1: icmp_seq=30 ttl=61 time=290 ms
64 bytes from 10.1.1.1: icmp_seq=31 ttl=61 time=381 ms
64 bytes from 10.1.1.1: icmp_seq=32 ttl=61 time=338 ms
64 bytes from 10.1.1.1: icmp_seq=33 ttl=61 time=255 ms
64 bytes from 10.1.1.1: icmp_seq=34 ttl=61 time=353 ms
64 bytes from 10.1.1.1: icmp_seq=35 ttl=61 time=275 ms
64 bytes from 10.1.1.1: icmp_seq=37 ttl=61 time=368 ms
64 bytes from 10.1.1.1: icmp_seq=38 ttl=61 time=358 ms
64 bytes from 10.1.1.1: icmp_seq=39 ttl=61 time=264 ms
64 bytes from 10.1.1.1: icmp_seq=40 ttl=61 time=271 ms
64 bytes from 10.1.1.1: icmp_seq=41 ttl=61 time=332 ms
64 bytes from 10.1.1.1: icmp_seq=42 ttl=61 time=250 ms
64 bytes from 10.1.1.1: icmp_seq=43 ttl=61 time=269 ms
64 bytes from 10.1.1.1: icmp_seq=44 ttl=61 time=255 ms
64 bytes from 10.1.1.1: icmp_seq=45 ttl=61 time=265 ms
64 bytes from 10.1.1.1: icmp_seq=46 ttl=61 time=282 ms
64 bytes from 10.1.1.1: icmp_seq=47 ttl=61 time=261 ms
64 bytes from 10.1.1.1: icmp_seq=48 ttl=61 time=338 ms
64 bytes from 10.1.1.1: icmp_seq=49 ttl=61 time=269 ms
64 bytes from 10.1.1.1: icmp_seq=50 ttl=61 time=341 ms
64 bytes from 10.1.1.1: icmp_seq=51 ttl=61 time=387 ms
64 bytes from 10.1.1.1: icmp_seq=52 ttl=61 time=342 ms
64 bytes from 10.1.1.1: icmp_seq=53 ttl=61 time=258 ms
64 bytes from 10.1.1.1: icmp_seq=54 ttl=61 time=325 ms
64 bytes from 10.1.1.1: icmp_seq=55 ttl=61 time=352 ms
64 bytes from 10.1.1.1: icmp_seq=56 ttl=61 time=347 ms
64 bytes from 10.1.1.1: icmp_seq=57 ttl=61 time=321 ms
64 bytes from 10.1.1.1: icmp_seq=59 ttl=61 time=490 ms
64 bytes from 10.1.1.1: icmp_seq=60 ttl=61 time=478 ms
64 bytes from 10.1.1.1: icmp_seq=61 ttl=61 time=385 ms
64 bytes from 10.1.1.1: icmp_seq=62 ttl=61 time=486 ms
64 bytes from 10.1.1.1: icmp_seq=63 ttl=61 time=562 ms
64 bytes from 10.1.1.1: icmp_seq=64 ttl=61 time=475 ms
64 bytes from 10.1.1.1: icmp_seq=65 ttl=61 time=439 ms
64 bytes from 10.1.1.1: icmp_seq=67 ttl=61 time=571 ms
64 bytes from 10.1.1.1: icmp_seq=68 ttl=61 time=533 ms
64 bytes from 10.1.1.1: icmp_seq=69 ttl=61 time=528 ms
64 bytes from 10.1.1.1: icmp_seq=70 ttl=61 time=403 ms
64 bytes from 10.1.1.1: icmp_seq=72 ttl=61 time=396 ms
64 bytes from 10.1.1.1: icmp_seq=73 ttl=61 time=361 ms
64 bytes from 10.1.1.1: icmp_seq=75 ttl=61 time=470 ms
64 bytes from 10.1.1.1: icmp_seq=77 ttl=61 time=675 ms
64 bytes from 10.1.1.1: icmp_seq=78 ttl=61 time=531 ms
64 bytes from 10.1.1.1: icmp_seq=79 ttl=61 time=382 ms
64 bytes from 10.1.1.1: icmp_seq=80 ttl=61 time=381 ms
64 bytes from 10.1.1.1: icmp_seq=81 ttl=61 time=400 ms
64 bytes from 10.1.1.1: icmp_seq=82 ttl=61 time=551 ms
64 bytes from 10.1.1.1: icmp_seq=83 ttl=61 time=570 ms
64 bytes from 10.1.1.1: icmp_seq=84 ttl=61 time=565 ms
64 bytes from 10.1.1.1: icmp_seq=85 ttl=61 time=539 ms
64 bytes from 10.1.1.1: icmp_seq=86 ttl=61 time=386 ms
64 bytes from 10.1.1.1: icmp_seq=87 ttl=61 time=237 ms
// 3.Profil
64 bytes from 10.1.1.1: icmp_seq=88 ttl=61 time=12.6 ms
64 bytes from 10.1.1.1: icmp_seq=89 ttl=61 time=13.1 ms
64 bytes from 10.1.1.1: icmp_seq=90 ttl=61 time=13.3 ms
64 bytes from 10.1.1.1: icmp_seq=91 ttl=61 time=11.6 ms
64 bytes from 10.1.1.1: icmp_seq=92 ttl=61 time=13.2 ms
64 bytes from 10.1.1.1: icmp_seq=93 ttl=61 time=12.6 ms
64 bytes from 10.1.1.1: icmp_seq=94 ttl=61 time=13.0 ms
64 bytes from 10.1.1.1: icmp_seq=95 ttl=61 time=12.4 ms
64 bytes from 10.1.1.1: icmp_seq=96 ttl=61 time=11.5 ms
64 bytes from 10.1.1.1: icmp_seq=97 ttl=61 time=11.9 ms
64 bytes from 10.1.1.1: icmp_seq=98 ttl=61 time=13.5 ms
64 bytes from 10.1.1.1: icmp_seq=99 ttl=61 time=11.1 ms
64 bytes from 10.1.1.1: icmp_seq=100 ttl=61 time=11.9 ms
64 bytes from 10.1.1.1: icmp_seq=101 ttl=61 time=12.4 ms
64 bytes from 10.1.1.1: icmp_seq=102 ttl=61 time=12.7 ms
64 bytes from 10.1.1.1: icmp_seq=103 ttl=61 time=12.8 ms
64 bytes from 10.1.1.1: icmp_seq=104 ttl=61 time=12.8 ms
64 bytes from 10.1.1.1: icmp_seq=105 ttl=61 time=11.2 ms
64 bytes from 10.1.1.1: icmp_seq=106 ttl=61 time=12.7 ms
64 bytes from 10.1.1.1: icmp_seq=107 ttl=61 time=14.1 ms
64 bytes from 10.1.1.1: icmp_seq=108 ttl=61 time=13.0 ms
64 bytes from 10.1.1.1: icmp_seq=109 ttl=61 time=12.5 ms
64 bytes from 10.1.1.1: icmp_seq=110 ttl=61 time=20.0 ms
64 bytes from 10.1.1.1: icmp_seq=111 ttl=61 time=13.1 ms
64 bytes from 10.1.1.1: icmp_seq=112 ttl=61 time=12.3 ms
64 bytes from 10.1.1.1: icmp_seq=113 ttl=61 time=12.4 ms
64 bytes from 10.1.1.1: icmp_seq=114 ttl=61 time=11.4 ms
64 bytes from 10.1.1.1: icmp_seq=115 ttl=61 time=13.1 ms
64 bytes from 10.1.1.1: icmp_seq=116 ttl=61 time=12.4 ms
// 1.Profil
64 bytes from 10.1.1.1: icmp_seq=117 ttl=61 time=43.5 ms
64 bytes from 10.1.1.1: icmp_seq=118 ttl=61 time=67.6 ms
64 bytes from 10.1.1.1: icmp_seq=119 ttl=61 time=42.7 ms
64 bytes from 10.1.1.1: icmp_seq=120 ttl=61 time=52.1 ms
64 bytes from 10.1.1.1: icmp_seq=121 ttl=61 time=41.0 ms
64 bytes from 10.1.1.1: icmp_seq=122 ttl=61 time=47.1 ms
64 bytes from 10.1.1.1: icmp_seq=123 ttl=61 time=41.1 ms
64 bytes from 10.1.1.1: icmp_seq=124 ttl=61 time=58.0 ms
64 bytes from 10.1.1.1: icmp_seq=125 ttl=61 time=70.4 ms
64 bytes from 10.1.1.1: icmp_seq=126 ttl=61 time=54.6 ms
64 bytes from 10.1.1.1: icmp_seq=127 ttl=61 time=55.6 ms
64 bytes from 10.1.1.1: icmp_seq=128 ttl=61 time=53.1 ms
64 bytes from 10.1.1.1: icmp_seq=129 ttl=61 time=55.5 ms
64 bytes from 10.1.1.1: icmp_seq=130 ttl=61 time=53.1 ms
64 bytes from 10.1.1.1: icmp_seq=131 ttl=61 time=37.6 ms
64 bytes from 10.1.1.1: icmp_seq=132 ttl=61 time=52.9 ms
64 bytes from 10.1.1.1: icmp_seq=133 ttl=61 time=57.6 ms
64 bytes from 10.1.1.1: icmp_seq=134 ttl=61 time=47.0 ms
64 bytes from 10.1.1.1: icmp_seq=135 ttl=61 time=51.2 ms
64 bytes from 10.1.1.1: icmp_seq=136 ttl=61 time=47.1 ms
64 bytes from 10.1.1.1: icmp_seq=137 ttl=61 time=57.1 ms
64 bytes from 10.1.1.1: icmp_seq=138 ttl=61 time=56.0 ms
64 bytes from 10.1.1.1: icmp_seq=139 ttl=61 time=59.6 ms
64 bytes from 10.1.1.1: icmp_seq=140 ttl=61 time=47.0 ms
64 bytes from 10.1.1.1: icmp_seq=141 ttl=61 time=59.9 ms
64 bytes from 10.1.1.1: icmp_seq=142 ttl=61 time=54.9 ms
64 bytes from 10.1.1.1: icmp_seq=143 ttl=61 time=69.2 ms
64 bytes from 10.1.1.1: icmp_seq=144 ttl=61 time=42.6 ms
64 bytes from 10.1.1.1: icmp_seq=145 ttl=61 time=60.0 ms
64 bytes from 10.1.1.1: icmp_seq=146 ttl=61 time=40.3 ms
// 2. Profile
64 bytes from 10.1.1.1: icmp_seq=147 ttl=61 time=295 ms
64 bytes from 10.1.1.1: icmp_seq=148 ttl=61 time=293 ms
64 bytes from 10.1.1.1: icmp_seq=149 ttl=61 time=261 ms
```
-> Das NetEm hat 3 Profile im Abstand von ca. 30 oder ca. 60 Pakete
### Ploten der Ping Latenz
Schreiben eines Batch Files um die Ping NAchricht in eine csv Datei umzuschreiben. Damit man diese mit Hilfe von der Python lib panda und mathplolib als Graphen darstellen lassen kann.
## 7.4 Subjektiver Einfluss von Latenz und Paketverlust
### Verbindung mit netcat zwischen RaspberryPi und Laptop
Auf Port 3333 lauschen (mit RaspberryPi):
```shell
pi@raspberrypi:~ $ nc -l -p 3333
```
Verbinden mit lauschendem Partner (mit Laptop):
```shell
# nc <zieladresse> <zielport>
User@pop-os:~ $ nc 10.1.1.1 3333
```
Um zu überprüfen, ob TCP oder UDP verwendet wird:
- TCP:
```shell
user@pop-os:~$ nc -vz 10.1.1.1 3333
Connection to 10.1.1.1 3333 port [tcp/*] succeeded!
```
- UDP:
```shell
user@pop-os:~$ nc -vz -u 10.1.1.1 3333
Connection to 10.1.1.1 3333 port [udp/*] succeeded!
```
Wenn man nun auf RaspberryPi etwas in der Kommandozeile taucht dies auch beim Laptop auf. Umgekehrt genauso $\Rightarrow$ Standard-Inputs und Standard-Outputs sind
### Wireshark TCP vs UDP
#### TCP:

$\Rightarrow$ Bei TCP wird ein 3-Way-Handshake (SYN, SYN_ACK, ACK) durchgeführt.
#### UDP:

### Echtzeitübertragung
#### TCP
RaspberryPi:
```shell
arecord -f S16_LE -r 44100 -V mono -D hw:1,0 -c 1 -t raw | nc -l -p 3333
```
Hierbei
```shell
arecord -D hw:1,0 -f S16_LE -r 44100 -c 1 -t raw | sox -t raw -r 44100 -e signed -b 16 -c 1 - -t raw -c 2 -r 44100 - | nc -l -p 3333
```
Client:
```shell
netcat 10.1.1.1 3333 | aplay -f S16_LE -r 44100 -V stereo -D hw:1,0 -t raw -c 2
```
Hiermit wird erfolgreich eine Live-Übertragung etabliert (~1s Verzögerung)
#### UDP
RaspberryPi:
```shell
arecord -D hw:1,0 -f S16_LE -r 44100 -c 1 -t raw | sox -t raw -r 44100 -e signed -b 16 -c 1 - -t raw -c 2 -r 44100 - | nc -u -l -p 3333
```
Client:
```shell
netcat -u 10.1.1.1 3333 | aplay -f S16_LE -r 44100 -V stereo -D hw:1,0 -c 2 -t raw
```
(Bei Client muss einmal Enter gedrückt werden, damit der RaspberryPi weiß, an wen er die Pakete schicken muss).
Es gibt bei UDP keine deutliche Verschlechterung der Audioqualiät, aber es kommt gelegentlich zu Paketverlusten.
### 7.4.1 Latenzminimierung und Puffer
Einstellen der Pufferzeit mit:
`--buffer-time <X>`, wobei X die Zeit in µs ist
Pufferzeit (Sendeseite): 10000µs = 10ms
Pufferzeit (Empfängerseite): 10000µs = 10ms
$\Rightarrow$ Wiedergabe ist OK
Pufferzeit (Sendeseite): 20000µs = 20ms
Pufferzeit (Empfängerseite): 20000µs = 20ms
$\Rightarrow$ Wiedergabe (etwas) verzögert, aber Stabilität besser.
Die Pufferzeit kann beliebig verkleinert werden und trotzdem ist eine Signalübertragung möglich.
Allgemein lässt sich feststellen, dass die Übertragung bei TCP besser ist als bei UDP.
### 7.4.2 Paketverlust und Latenz
Es werden nun die NetEm-Profile durchgegangen:
#### TCP
**1.)** (10-25ms): Sinnvolle Übertragung möglich
**2.)** (30-70ms): Sinnvolle Übertragung möglich
**3.)** (200-400ms): Keine Übertragung mehr möglich
**4.)** (300-600ms): Keine Übertragung mehr möglich
#### UDP
**1.)** (10-25ms): Sinnvolle Übertragung möglich
**2.)** (30-70ms): Übertragung fehlerhaft (definitiv schlechter als TCP)
**3.)** (200-400ms): Keine Übertragung mehr möglich aber besser als bei TCP
**4.)** (300-600ms): Keine Übertragung mehr möglich
#### Dimensionierung der Pufferzeiten
Bei UDP kann man mit einer Pufferzeit von 1000ms unterbrechungsfrei übertragen werden, allerdings kommen manche Pakete in der falschen Reihenfolge an, wodurch das Signal verfälscht wird. Somit wäre ein sinnvolles Echtzeitgespräch nicht möglich.
Bei TCP hingegen kommen die Pakete in der richtigen Reihenfolge an, wodurch ein sinnvolles Echtzeitgespräch möglich wird.
(Allerdings bei beiden Protokollen: Hohe Latenz)
# Protokoll 8
## 8.3 Einfache OpenFlow Regeln
### Verbindung bereits möglich?
Nein
```shell
PS C:\Users\Leon-> ping 10.1.1.1
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Antwort von 10.1.1.120: Zielhost nicht erreichbar.
Zeitüberschreitung der Anforderung.
```
### Match zur Kommunikation zwischen RaspberryPi (Port #2 SDN-Switch) und Endgerät (Port #3 SDN-Switch)
```shell!
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "table=0 in_port=2 actions=3"
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "table=0 in_port=3 actions=2"
root@OpenWrt:~# ovs-ofctl dump-flows ovs-br
cookie=0x0, duration=10.483s, table=0, n_packets=10, n_bytes=642, in_port="eth0.2" actions=output:"eth0.3"
cookie=0x0, duration=4.628s, table=0, n_packets=18, n_bytes=1660, in_port="eth0.3" actions=output:"eth0.2"
```
Ping ist nun möglich:
```shell!
PS C:\Users\user-> ping 10.1.1.1
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Antwort von 10.1.1.1: Bytes=32 Zeit=2ms TTL=64
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=64
Antwort von 10.1.1.1: Bytes=32 Zeit=2ms TTL=64
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=64
Ping-Statistik für 10.1.1.1:
Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
(0% Verlust),
Ca. Zeitangaben in Millisek.:
Minimum = 1ms, Maximum = 2ms, Mittelwert = 1ms
```
$\Rightarrow$ Paketcounter: 4, Bytecounter: 32
### MAC-Adressen festellen
- RaspberryPi: `ip addr`
b8:27:eb:fc:10:f5
- Notebook: Windows Network Manager
00:e0:4c:6b:5d:64 (muss für andere Geräte geändert werden)
### Hinzufügen der MAC Regeln
```shell
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "arp,actions=flood"
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "dl_dst=00:E0:4C:6B:5D:64,dl_src=b8:27:eb:fc:10:f5,actions=3"
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "dl_src=00:E0:4C:6B:5D:64,dl_dst=b8:27:eb:fc:10:f5,actions=2"
```
### Hinzufügen der IP Regeln
Alte Regeln löschen:
```shell
root@OpenWrt:~# ovs-ofctl del-flows ovs-br
```
Hinzufügen der neuen Regeln:
```shell
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "arp,actions=flood"
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "ip,nw_src=10.1.1.1,nw_dst=10.1.1.120,actions=dec_ttl,3"
root@OpenWrt:~# ovs-ofctl add-flow ovs-br "ip,nw_dst=10.1.1.1,nw_src=10.1.1.120,actions=dec_ttl,2"
```
Für Ping mit TTL=1 (nach Reduzieren TTL=0 und verwerfen)
```shell
PS C:\Users\user-> ping 10.1.1.1 -i 1
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Zeitüberschreitung der Anforderung.
Ping-Statistik für 10.1.1.1:
Pakete: Gesendet = 1, Empfangen = 0, Verloren = 1
(100% Verlust),
STRG-C
PS C:\Users\user-> ping 10.1.1.1 -i 2
Ping wird ausgeführt für 10.1.1.1 mit 32 Bytes Daten:
Antwort von 10.1.1.1: Bytes=32 Zeit=3ms TTL=63
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=63
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=63
Antwort von 10.1.1.1: Bytes=32 Zeit=1ms TTL=63
Ping-Statistik für 10.1.1.1:
Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
(0% Verlust),
Ca. Zeitangaben in Millisek.:
Minimum = 1ms, Maximum = 3ms, Mittelwert = 1ms
```
## 8.4 Nachbau eines statischen NAT mit Firewall
RaspberryPi: `static_router` auf `10.1.1.254` geändert (von `10.1.1.100` aus vorherigen Aufgaben)
### Match-Action-Regeln
```shell
ovs-ofctl add-flow ovs-br "priority=100,arp,arp_tpa=10.1.1.254,in_port=2,actions=set_field:2->arp_op,move:arp_spa->arp_tpa,set_field:10.1.1.254->arp_spa,move:arp_sha->arp_tha,set_field:08:55:31:34:9e:aa->arp_sha,move:eth_src->eth_dst,set_field:08:55:31:34:9e:aa->eth_src,in_port"
ovs-ofctl add-flow ovs-br "priority=100,arp,arp_tpa=10.1.123.254,in_port=3,actions=set_field:2->arp_op,move:arp_spa->arp_tpa,set_field:10.1.123.254->arp_spa,move:arp_sha->arp_tha,set_field:08:55:31:34:9e:ab->arp_sha,move:eth_src->eth_dst,set_field:08:55:31:34:9e:ab->eth_src,in_port"
```

Weiterleitung Port#2 $\leftrightarrow$ Port#3:
```shell
ovs-ofctl add-flow ovs-br "priority=100,ip,in_port=3,nw_dst=10.1.1.1 actions=set_field:b8:27:eb:fc:10:f5->eth_dst, set_field:08:55:31:34:9e:ab->eth_src,dec_ttl,2"
ovs-ofctl add-flow ovs-br "priority=100,ip,in_port=2,nw_dst=10.1.123.120 actions=set_field:08:55:31:34:9e:aa->eth_src, set_field:00:e0:4c:6b:5d:64->eth_dst,dec_ttl,3"
```
Ping Test:
```shell
PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=64 time=1.95 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=64 time=0.921 ms
64 bytes from 10.1.1.1: icmp_seq=3 ttl=64 time=0.922 ms
64 bytes from 10.1.1.1: icmp_seq=4 ttl=64 time=0.903 ms
--- 10.1.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 0.903/1.172/1.945/0.445 ms
```
Droppen aller IP-Pakete aus Subnetz 10.1.1.0/24:
```shell
ovs-ofctl add-flow ovs-br "priority=1500,ip,nw_dst=10.1.1.0/24,actions=drop"
```
Regeln für indirekte Aufrufe (10.1.123.254:12221 nach Port 22 (SSH) des RapberryPi)
```shell
ovs-ofctl add-flow ovs-br "priority=2000,tcp,nw_dst=10.1.123.254,tp_dst=12221, actions=mod_nw_dst:10.1.1.1,mod_tp_dst:22,mod_dl_src:08:55:31:34:9e:aa,mod_dl_dst:b8:27:eb:fc:10:f5,2"
ovs-ofctl add-flow ovs-br "priority=2000,tcp,in_port=2,nw_dst=10.1.123.0/24,tp_src=22, actions=mod_tp_src:12221,mod_nw_src:10.1.123.254,mod_dl_src:08:55:31:34:9e:ab,mod_dl_dst:00:e0:4c:6b:5d:64,3"
```
$\Rightarrow$ SSH funktioniert, Ping nicht möglich
Verbindung zu Dash-Web-Server:
Neue Regeln:
```shell
ovs-ofctl add-flow ovs-br "priority=2000,tcp,nw_dst=10.1.1.254,tp_dst=10810, actions=mod_nw_dst:10.1.123.120,mod_dl_src:08:55:31:34:9e:ab,mod_dl_dst:00:e0:4c:6b:5d:64,mod_nw_src:10.1.123.254,3"
ovs-ofctl add-flow ovs-br "priority=1000,tcp,nw_dst=10.1.123.254,actions=mod_nw_dst:10.1.1.1,mod_dl_src:08:55:31:34:9e:aa,mod_dl_dst:b8:27:eb:fc:10:f5,mod_nw_src:10.1.1.254,2"
```
Verbindungen sind wieder möglich und Temperaturverlauf kann am Endgerät (Laptop) über `127.0.0.1:10810`
tcp_client.py, tcp_server.py und temp_http.py sind in GitLab.
#### Übersicht aller Regeln
```shell
root@OpenWrt:~# ovs-ofctl dump-flows ovs-br
cookie=0x0, duration=830.881s, table=0, n_packets=78, n_bytes=8485, priority=2000,tcp,nw_dst=10.1.123.254,tp_dst=12221 actions=mod_nw_dst:10.1.1.1,mod_tp_dst:22,mod_dl_src:08:55:31:34:9e:aa,mod_dl_dst:b8:27:eb:fc:10:f5,output:"eth0.2"
cookie=0x0, duration=823.096s, table=0, n_packets=8, n_bytes=552, priority=2000,tcp,nw_dst=10.1.1.254,tp_dst=10810 actions=mod_nw_dst:10.1.123.120,mod_dl_src:08:55:31:34:9e:ab,mod_dl_dst:00:e0:4c:6b:5d:64,mod_nw_src:10.1.123.254,output:"eth0.3"
cookie=0x0, duration=827.144s, table=0, n_packets=64, n_bytes=9728, priority=2000,tcp,in_port="eth0.2",nw_dst=10.1.123.0/24,tp_src=22 actions=mod_tp_src:12221,mod_nw_src:10.1.123.254,mod_dl_src:08:55:31:34:9e:ab,mod_dl_dst:00:e0:4c:6b:5d:64,output:"eth0.3"
cookie=0x0, duration=834.147s, table=0, n_packets=0, n_bytes=0, priority=1500,ip,nw_dst=10.1.1.0/24 actions=drop
cookie=0x0, duration=819.254s, table=0, n_packets=6, n_bytes=404, priority=1000,tcp,nw_dst=10.1.123.254 actions=mod_nw_dst:10.1.1.1,mod_dl_src:08:55:31:34:9e:aa,mod_dl_dst:b8:27:eb:fc:10:f5,mod_nw_src:10.1.1.254,output:"eth0.2"
cookie=0x0, duration=847.139s, table=0, n_packets=18, n_bytes=1080, priority=100,arp,in_port="eth0.2",arp_tpa=10.1.1.254 actions=load:0x2->NXM_OF_ARP_OP[],move:NXM_OF_ARP_SPA[]->NXM_OF_ARP_TPA[],load:0xa0101fe->NXM_OF_ARP_SPA[],move:NXM_NX_ARP_SHA[]->NXM_NX_ARP_THA[],load:0x85531349eaa->NXM_NX_ARP_SHA[],move:NXM_OF_ETH_SRC[]->NXM_OF_ETH_DST[],mod_dl_src:08:55:31:34:9e:aa,IN_PORT
cookie=0x0, duration=843.286s, table=0, n_packets=3, n_bytes=180, priority=100,arp,in_port="eth0.3",arp_tpa=10.1.123.254 actions=load:0x2->NXM_OF_ARP_OP[],move:NXM_OF_ARP_SPA[]->NXM_OF_ARP_TPA[],load:0xa017bfe->NXM_OF_ARP_SPA[],move:NXM_NX_ARP_SHA[]->NXM_NX_ARP_THA[],load:0x85531349eab->NXM_NX_ARP_SHA[],move:NXM_OF_ETH_SRC[]->NXM_OF_ETH_DST[],mod_dl_src:08:55:31:34:9e:ab,IN_PORT
cookie=0x0, duration=840.242s, table=0, n_packets=0, n_bytes=0, priority=100,ip,in_port="eth0.3",nw_dst=10.1.1.1 actions=mod_dl_dst:b8:27:eb:fc:10:f5,mod_dl_src:08:55:31:34:9e:ab,dec_ttl,output:"eth0.2"
cookie=0x0, duration=836.798s, table=0, n_packets=0, n_bytes=0, priority=100,ip,in_port="eth0.2",nw_dst=10.1.123.120 actions=mod_dl_src:08:55:31:34:9e:aa,mod_dl_dst:00:e0:4c:6b:5d:64,dec_ttl,output:"eth0.3"
```