or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
P4 09
龍帆軒 楊舒翔 20201123
使用自己定義的topology
這次修改了p4lang/tutorials/exercise裡的 basic

將原本的四角形拓樸改成兩個switch各接2個host
使他們可以互相傳送封包
因為這次並沒有使用controller 所以table entries跟rules都要自己寫進switch

在pod-topo資料夾裡新增 s1-runtime.json跟s2-runtime.json
在json檔裡寫好需要的table entry
之後新增topology.json 將自己的拓樸定義好

之後在basic.p4 檔寫好封包的傳送
寫好後執行

make run
在mininet下執行
xterm h1 h2
可以輸入
./send.py 10.0.2.2 "hello hi"
測試封包可不可以成功傳送接收的輸入
./recieve.py
sniff封包可以看到成功傳到了
利用參數輸入tcp的dport來判斷如何傳遞封包
在使用send.py寄送封包時可使用 –tcp_dport [X]來設定tcp的dport
之後在parse過程中嘗試提取出封包中tcp的部分,利用tcp的dport來當作如何傳遞封包的依據
首先定義好s1,s2,s3三個switch

ex : s1-runtime.json
然後將topology定義好

使用的topology圖示如下 :
首先新增一個header tcp_t

再將剛剛新增的header加入struct中

修改 parser 使其可以將 tcp 的 header parse 出來

在table中新增對應的指令

比對tcp的dport,如果符合我們寫好的match情況,就會執行tcp_forward。
這邊在forwarding的時候,除了把傳遞路徑設定好之外,也同時把tcp的dport設成1234。
因為receive.py中會判斷傳來的封包tcp的dport欄位是不是1234,如果不是的話就不會印出packet的資訊。
receive.py中的handle_pkt
在這邊所寫的table tcp也分別寫入s1~s3三個switch的json檔中

由於參數dport有可能是1,2,3三種,所以寫了三個對應的match情況。
在h1視窗中輸入指令

./send.py 10.0.2.2 “test” –tcp_dport 2
在h2中成功收到封包,且tcp中的dport也成功從2改成了1234

tags:
P4