Ở phần trước mình đã hướng dẫn các bạn cài đặt môi trường và công cụ rồi, các bạn có thể xem ở đây
Tiếp theo ở phần này mình sẽ hướng dẫn các bạn mô phỏng mạng SDN trên ONOS. Ở phần trước nếu các bạn chạy ONOS bằng lệnh ./start mà bị lỗi thì mình có thể khởi động ONOS bằng lệnh sau, đảm bảo chạy ngon lành, lúc tắt đi chỉ cần Ctrl+C
Xây dựng kịch bản mô phỏng
Chúng ta sẽ sử dụng python để viết kịch bản mô phỏng, ở đây thì topo mạng của mình gồm có 3 hosts và 3 switch, tùy vào yêu cầu mô phỏng thì các bạn xây dựng kịch bản tương tự, kịch bản của mình như sau:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <span class="token keyword">from</span> mininet<span class="token punctuation">.</span>topo <span class="token keyword">import</span> Topo <span class="token keyword">class</span> <span class="token class-name">MyTopo</span><span class="token punctuation">(</span> Topo <span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token string">"Simple topology example."</span> <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span> self <span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token string">"Create custom topo."</span> Topo<span class="token punctuation">.</span>__init__<span class="token punctuation">(</span> self <span class="token punctuation">)</span> <span class="token comment"># add host</span> h1 <span class="token operator">=</span> self<span class="token punctuation">.</span>addHost<span class="token punctuation">(</span><span class="token string">'h1'</span><span class="token punctuation">)</span> h2 <span class="token operator">=</span> self<span class="token punctuation">.</span>addHost<span class="token punctuation">(</span><span class="token string">'h2'</span><span class="token punctuation">)</span> h3 <span class="token operator">=</span> self<span class="token punctuation">.</span>addHost<span class="token punctuation">(</span><span class="token string">'h3'</span><span class="token punctuation">)</span> <span class="token comment"># add switch</span> s1 <span class="token operator">=</span> self<span class="token punctuation">.</span>addSwitch<span class="token punctuation">(</span><span class="token string">'s1'</span><span class="token punctuation">)</span> s2 <span class="token operator">=</span> self<span class="token punctuation">.</span>addSwitch<span class="token punctuation">(</span><span class="token string">'s2'</span><span class="token punctuation">)</span> s3 <span class="token operator">=</span> self<span class="token punctuation">.</span>addSwitch<span class="token punctuation">(</span><span class="token string">'s3'</span><span class="token punctuation">)</span> <span class="token comment"># add connection</span> self<span class="token punctuation">.</span>addLink<span class="token punctuation">(</span>s1<span class="token punctuation">,</span> s2<span class="token punctuation">)</span> self<span class="token punctuation">.</span>addLink<span class="token punctuation">(</span>s3<span class="token punctuation">,</span> s2<span class="token punctuation">)</span> self<span class="token punctuation">.</span>addLink<span class="token punctuation">(</span>s3<span class="token punctuation">,</span> s1<span class="token punctuation">)</span> self<span class="token punctuation">.</span>addLink<span class="token punctuation">(</span>s1<span class="token punctuation">,</span> h1<span class="token punctuation">)</span> self<span class="token punctuation">.</span>addLink<span class="token punctuation">(</span>s2<span class="token punctuation">,</span> h2<span class="token punctuation">)</span> self<span class="token punctuation">.</span>addLink<span class="token punctuation">(</span>s3<span class="token punctuation">,</span> h3<span class="token punctuation">)</span> <span class="token comment"># sudo mn --controller=remote,ip=127.0.0.1,port=6653 --custom code2.py --topo tp</span> topos <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">'tp'</span><span class="token punctuation">:</span> <span class="token punctuation">(</span> <span class="token keyword">lambda</span><span class="token punctuation">:</span> MyTopo<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">}</span> |
Sau đó chạy câu lệnh như mình comment, thay code2.py bằng tên file của bạn, với local là thư mục chứa file
Khi đó thì màn hình onos sẽ hiển thị như sau:
Cơ mà lúc này vẫn chưa ping được vì chúng ta chưa cấu hình định tuyến.
Cấu hình định tuyến tự động
Các bạn vào Menu/Application và bật cho mình 2 cái này lên
Cái này cho phép sử dụng giao thức OpenFlow
Còn cái này cho phép định tuyến tự động.
Giờ thì ping ngon rồi
Cấu hình định tuyến thủ công.
Trước tiên các bạn vào Menu/Application và tắt Reactive Forwading đi rồi bật ARP/NDP proxy (lúc này ping giữa 2 host sẽ không thành công do đã tắt chức năng định tuyến tự động ở phần trên)
Ở đây mình đã tạo file cấu hình có nội dung như sau:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | { "flows": [ { "id": "52917298863470654", "tableId": "0", "appId": "org.onosproject.net.intent", "groupId": 0, "priority": 55, "timeout": 0, "isPermanent": true, "deviceId": "of:0000000000000001", // id của switch "state": "ADDED", "life": 1689, "packets": 0, "bytes": 0, "liveType": "UNKNOWN", "lastSeen": 1557803155885, "treatment": { "instructions": [ { "type": "OUTPUT", // cổng ra số 2 "port": "2" } ], "deferred": [] }, "selector": { "criteria": [ { "type": "IN_PORT", // cổng vào số 3 "port": 3 }, { "type": "ETH_DST", "mac": "8E:BB:58:81:5D:4D" // mac của host đích đến }, { "type": "ETH_SRC", "mac": "62:D6:0A:99:C5:DB" // mac của host gửi, mấy cái sau tương tự } ] } }, { "id": "52917298863470654", "tableId": "0", "appId": "org.onosproject.net.intent", "groupId": 0, "priority": 55, "timeout": 0, "isPermanent": true, "deviceId": "of:0000000000000001", "state": "ADDED", "life": 1689, "packets": 0, "bytes": 0, "liveType": "UNKNOWN", "lastSeen": 1557803155885, "treatment": { "instructions": [ { "type": "OUTPUT", "port": "3" } ], "deferred": [] }, "selector": { "criteria": [ { "type": "IN_PORT", "port": 2 }, { "type": "ETH_DST", "mac": "62:D6:0A:99:C5:DB" }, { "type": "ETH_SRC", "mac": "8E:BB:58:81:5D:4D" } ] } }, { "id": "52917298863470654", "tableId": "0", "appId": "org.onosproject.net.intent", "groupId": 0, "priority": 55, "timeout": 0, "isPermanent": true, "deviceId": "of:0000000000000003", "life": 1689, "packets": 0, "bytes": 0, "liveType": "UNKNOWN", "treatment": { "instructions": [ { "type": "OUTPUT", "port": "1" } ], "deferred": [] }, "selector": { "criteria": [ { "type": "IN_PORT", "port": 2 }, { "type": "ETH_DST", "mac": "8E:BB:58:81:5D:4D" }, { "type": "ETH_SRC", "mac": "62:D6:0A:99:C5:DB" } ] } }, { "id": "52917298863470654", "tableId": "0", "appId": "org.onosproject.net.intent", "groupId": 0, "priority": 55, "timeout": 0, "isPermanent": true, "deviceId": "of:0000000000000003", "state": "ADDED", "life": 1689, "packets": 0, "bytes": 0, "liveType": "UNKNOWN", "lastSeen": 1557803155885, "treatment": { "instructions": [ { "type": "OUTPUT", "port": "2" } ], "deferred": [] }, "selector": { "criteria": [ { "type": "IN_PORT", "port": 1 }, { "type": "ETH_DST", "mac": "62:D6:0A:99:C5:DB" }, { "type": "ETH_SRC", "mac": "8E:BB:58:81:5D:4D" } ] } }, { "id": "52917298863470654", "tableId": "0", "appId": "org.onosproject.net.intent", "groupId": 0, "priority": 55, "timeout": 0, "isPermanent": true, "deviceId": "of:0000000000000002", "state": "ADDED", "life": 1689, "packets": 0, "bytes": 0, "liveType": "UNKNOWN", "lastSeen": 1557803155885, "treatment": { "instructions": [ { "type": "OUTPUT", "port": "3" } ], "deferred": [] }, "selector": { "criteria": [ { "type": "IN_PORT", "port": 2 }, { "type": "ETH_DST", "mac": "8E:BB:58:81:5D:4D" }, { "type": "ETH_SRC", "mac": "62:D6:0A:99:C5:DB" } ] } }, { "id": "52917298863470654", "tableId": "0", "appId": "org.onosproject.net.intent", "groupId": 0, "priority": 55, "timeout": 0, "isPermanent": true, "deviceId": "of:0000000000000002", "state": "ADDED", "life": 1689, "packets": 0, "bytes": 0, "liveType": "UNKNOWN", "lastSeen": 1557803155885, "treatment": { "instructions": [ { "type": "OUTPUT", "port": "2" } ], "deferred": [] }, "selector": { "criteria": [ { "type": "IN_PORT", "port": 3 }, { "type": "ETH_DST", "mac": "62:D6:0A:99:C5:DB" }, { "type": "ETH_SRC", "mac": "8E:BB:58:81:5D:4D" } ] } } ] } |
Sau đó các bạn vào đường dẫn sau và dán code đó vào rồi nhấn Try it out!
http://localhost:8181/onos/v1/docs/#!/flows/post_flows
Giờ thì ping lại ổn Lưu ý là gói tin đi qua mạng SDN thì TTL không bị giảm nhé
Qua 2 bài viết này thì mình đã hướng dẫn các bạn cài đặt môi trường và mô phỏng mạng SDN qua mininet, onos. Đối với mô phỏng SDN-IP thì phức tạp hơn, các bạn có thể xem hướng dẫn ở đây
Tài liệu tham khảo: