Topology API 概述
Topology 导入/导出 API 允许以编程方式将网络拓扑导入 Riverbed 应用或从中导出,数据存放在一个遵循 Topology Exchange File(TEF)格式的自描述文本文件中。TEF 文件包含网络中节点与链路的信息。为了让 TEF 文件格式足够灵活、可用于不同类型的网络,文件中还包含描述节点与链路方式的元信息。
Topology Exchange File(TEF)格式
该文件格式的正式描述如下。
\t表示制表符<>对中的术语必须是字符串或数字,且不得包含任何\t字符<>或{}对之外的文本是字面关键字(必须严格按照所示拼写)- 以
#开头的行是注释行,会被忽略
图 20:Topology Exchange File(TEF)格式
Number of Node Attributes: <number of node attributes>
# This section describes which node attributes are to be imported
{Node Attribute Description Section}
Number of Nodes: <number of nodes in network>
# Here starts the attribute values for the nodes
<node1 name>\t<node1 model>\t<node1 attribute1 value>\t<node1 attribute2 value> …
<node2 name>\t<node2 model>\t<node2 attribute1 value>\t<node2 attribute2 value> …
……
……
Number of Link Attributes: <number of link attributes>
{Link Attribute Description Section}
<link1 name>\t<link1 model>\t<link1 source node name>\t
<link1 destination node name>\t <link1 attribute1 value>\t
<link1 attribute2 value> …
<link2 name>\t<link2 model>\t<link2 source node name>\t
<link2 destination node name>\t <link2 attribute1 value>\t
<link2 attribute2 value> …
……
……
如图 20所示,TEF 由两个主要部分组成:节点部分和链路部分。在节点部分中,Node Attribute Description Section 为节点定义一个模式(schema),描述节点属性的一组公共子集。应用导入该文件时,会先创建节点,然后按照该模式以及文件后续行中的属性值,为每个节点设置这些属性的值。更具体地说,在 Node Attribute Description Section 中,每一行定义一个属性的名称和类型。
例如,假设所有节点都有 x position、y position 和 icon name 属性,并且希望在导入操作中设置这些值,那么该部分应为:
icon name: string
x position: double
y position: double
通过此特性导入或导出的属性必须是 int、string 或 double 数据类型。
Number of Nodes 行指定网络中节点的数量。其后每个节点占一行,列出该节点的属性值(在上述示例中为 icon、x position 和 y position)。节点名和节点模型值始终列在每行的开头,其后才是属性值。例如,图 21展示了一个指定五个节点的节点部分,其中一个节点的模型是 switch,另一个的模型是 site。
图 21:TEF 文件的节点属性描述部分示例
Number of Node Attributes : 3
icon name: string
x position: double
y position: double
Number of Nodes: 5
# name, model, icon, x position, y position
node_0 switch cabletv -77.370000 39.760000
node_1 site cabletv -75.690000 38.490000
node_2 site cabletv -76.310000 36.490000
node_3 site cabletv -78.440000 36.490000
node_4 site cabletv -79.090000 38.510000
当使用 Imex 包导入该文件时,将创建 5 个节点,所有节点的 icon 均设置为 “cabletv”,位置设置为指定的数值。
使用此文件格式时,导入的网络是“扁平”(flat)的,即所有节点和链路都位于顶层,无法创建子网。
再假设每个节点新增一个名为 “cost” 的 double 类型属性。图 22展示了加入该属性后的前述 TEF(注意:switch 和 site 两种模型都必须具有 double 类型的 “cost” 属性,导入才能无错误;否则会生成错误消息,说明包无法为某些节点设置 “cost”)。
图 22:向 TEF 文件添加新属性
Number of Node Attributes : 4
icon name: string
x position: double
y position: double
cost: double
Number of Nodes 5
# name, model, icon, x position, y position, cost
node_0 switch cabletv -77.370000 39.760000 1000.0
node_1 site cabletv -75.690000 38.490000 2000.0
node_2 site cabletv -76.310000 36.490000 2000.0
node_3 site cabletv -78.440000 36.490000 2000.0
node_4 site cabletv -79.090000 38.510000 2000.0
链路部分与节点部分非常相似,区别在于不需要给出链路数量(Imex 假定 Link Attribute Description Section 之后的每一行都代表一条链路)。此外还有两个必填属性:源节点名和目的节点名。这两个属性的值必须与节点部分中的节点名一致,应用才能知道每条链路连接的是哪两个节点。链路是双向的。图 23包含一个链路部分的示例。
图 23:TEF 文件的链路属性描述部分示例
Number of Link Attributes : 4
Number of Fibers: int
Number of Wavelengths per Fiber : int
Bandwidth per Wavelength (Mbps) : double
Actual Length : double
# name, model, source, dest, wave, fibers, Mbps, length (km)
duplex_0 fiber_bundle node_0 node_1 1 4 51.840000 80.000000
duplex_4 SONET node_0 node_4 1 4 150.40000 80.000000
duplex_1 fiber_bundle node_1 node_2 1 4 51.840000 80.000000
duplex_2 fiber_bundle node_2 node_3 1 4 51.840000 80.000000
duplex_3 fiber_bundle node_3 node_4 1 4 51.840000 80.000000
从第一条链路行可以看出,存在一条名为 duplex_0 的链路,其模型为 “fiber_bundle”,连接 node_0 与 node_1;它每根光纤有 1 个波长,共 4 根光纤,每波长带宽为 51.84 Mbps,长度为 80.0。