資訊人筆記

Work hard, Have fun, Make history!

使用者工具

網站工具


ccis_lab:sdn:ryu:ryu_topology_discovery_code_analysis:ryu_topology_discovery_code_analysis_1

Ryu 拓墣探勘程式碼分析(一): gui_topology.py

0x00 前言

Ryu 在 ryu/app/gui_topology/gui_topology.py 這支程式提供了圖形化介面的拓樸視圖

在本篇中我們將分析 gui_topology.py 的原始碼

以此為出發點,在後續章節一步步深入解析 Ryu 中的拓樸探勘相關程式碼


0x01 Topology Viewer

關於程式的啟動方式可以參考 Topology Viewer Document

在底下的原始碼中也可以看到 Usage Example 的註解,教你如何在 ryu 中啟動這支程式

<html>
<style>
pre { box-shadow: none; }
table, td { border: none; }
</style>

<body>
<script type='text/javascript' src='gistfy-app.herokuapp.com/github/nike1000/ryu/ryu/app/gui_topology/gui_topology.py?branch=master&lang=python&style=github'></script>
</body>
</html>

—-

=====0x02 GUIServerApp class=====

<html>
<style>
pre { box-shadow: none; }
table, td { border: none; }
</style>

<body>
<script type='text/javascript' src='
gistfy-app.herokuapp.com/github/nike1000/ryu/ryu/app/gui_topology/gui_topology.py?branch=master&slice=40:50&lang=python&style=github'></script>
</body>
</html>

首先,我們看到 GUIServerApp 這個類別繼承了 app_manager.RyuApp 這個類別

app_manager.RyuApp 這個類別是 Ryu 應用程式的基礎類別

我們看看 RyuApp 的原始碼

<html>
<style>
pre { box-shadow: none; }
table, td { border: none; }
</style>

<body>
<script type='text/javascript' src='gistfy-app.herokuapp.com/github/nike1000/ryu/ryu/base/app_manager.py?branch=master&slice=91:123&lang=python&style=github'></script>
</body>
</html>

這邊註解提到在 ryu-manager 將所需的 Ryu application modules 載入後會將 RyuApp 的 subclasses 實例化


<html>
<style>
pre { box-shadow: none; }
table, td { border: none; }
</style>

<body>
<script type='text/javascript' src='
gistfy-app.herokuapp.com/github/nike1000/ryu/ryu/base/app_manager.py?branch=master&slice=153:172&lang=python&style=github'></script>
</body>
</html>

在 RyuApp 的 __init__ 中有個變數 name,Ryu 是用這個變數來識別各個應用程式,以此將訊息 (如 Event) 做路由

而這個變數是由 __class__.__name__ 來取得目前類別的名稱,在此就是 GUIServerApp

_CONTEXTS 則是一個 dictionary,用來決定這個 Ryu 應用程式所要使用的 context

ccis_lab/sdn/ryu/ryu_topology_discovery_code_analysis/ryu_topology_discovery_code_analysis_1.txt · 上一次變更: 127.0.0.1