floodlight初步学习

floodlight 初步学习

floodlight 配置

floodlight 模块加载配置

floodlight 可以通过配置来加载不通的模块。

  • 在src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule 可以看到编译出来的全部模块.

  • 但是编译出来的模块不一定全部使用,在src/main/resources/floodlightdefault.properties 文件中,表示了一些默认加载的模块,而这个配置文件默认包含了大部分的模块。 其中还有一些端口的配置信息,比如控制器端口,以及http服务的端口,等等.

floodlight 日志等级配置

日志信息有时候会提供一些帮助,floodlight 使用org.slf4j.Logger来提供不同级别的日志. 默认的日志级别是INFO. 通过下面的命令来控制日志级别。

$ java -Dlogback.configurationFile=logback.xml -jar floodlight.jar

所以,可以通过更改logback.xml 来修改日志级别.

其他配置

一些其他的配置,如安全性配置,由于暂时永不到,会在之后的学习中介绍.

static entry pusher API

介绍

static entry pusher是floodlight的一个模块,可以让用户手动添加流表和组表在一个of网络中.

主动和被动的流表植入

OpenFlow 支持两种流表植入方法,主动和被动的流表植入.

  • 被动的表项植入: 在匹配不到的情况下发生,数据包会发送到控制器,控制器处理这个包,添加合适的entries,并且让交换机继续转发.
  • 主动的表项植入: 在包到来之前,就添加好,主要匹配到该项,就不会上发到控制器.

注意, floodlight 默认使用被动的表项添加机制,如果想要单独使用静态的路径。 必须从配置文件中移除Forwarding模块;

静态表项植入怎样使用?

使用Curl来获得REST API

  • 使用REST CALL 来检索floodlight 的数据:

    $ curl http://<controller-ip>:8080/wm/core/controller/switches/json
  • 使用curl 提供数据给floodlight:

    $ curl http://<controller-ip>:8080/wm/core/switch/all/role/json -X POST -d '{"role":"MASTER"}'
  • 对于返回的json数据,python可以用来解析json的数据

    curl http://<controller-ip>:8080/wm/core/controller/switches/json | python -m json.tool

使用python来获得REST API

import httplib
import json

class StaticFlowPusher(object):

def __init__(self, server):
self.server = server #初始化,获得服务器ip

def get(self, data):
ret = self.rest_call({}, 'GET')
return json.loads(ret[2])

def set(self, data):
ret = self.rest_call(data, 'POST') #设置一个flow entry
return ret[0] == 200

def remove(self, objtype, data): #移除一个flow entry
ret = self.rest_call(data, 'DELETE')
return ret[0] == 200

def rest_call(self, data, action): #获取 REST API
path = '/wm/staticflowpusher/json' ## 添加静态路由
headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
} ##请求头部
body = json.dumps(data) #将数据转换换成字符串
conn = httplib.HTTPConnection(self.server, 8080) ##建立链接
conn.request(action, path, body, headers) ##向相关api发送HTTP请求: 动作, 路径(api),内容,头部;
response = conn.getresponse() ##得到请求回应
ret = (response.status, response.reason, response.read())
print ret ##打印回应
conn.close()
return ret

pusher = StaticFlowPusher('localhost')

flow1 = {
'switch':"00:00:00:00:00:00:00:01",
"name":"flow_mod_1",
"cookie":"0",
"priority":"32768",
"in_port":"1",
"active":"true",
"actions":"output=flood"
}

flow2 = {
'switch':"00:00:00:00:00:00:00:01",
"name":"flow_mod_2",
"cookie":"0",
"priority":"32768",
"in_port":"2",
"active":"true",
"actions":"output=flood"
}

pusher.set(flow1)
pusher.set(flow2)

下面是大部分API的ULI:
URI

下面是几个例子:
Add/Delete entry URI: /wm//json
List entries URI: /wm//json
Clear entries URI: /wm/</json

: staticentrypusher

Adding a Flow

例如, 想要插入一个flow在switch1上,收到包来自端口1,并且输出到端口2,可以构造一个JSON string. 并通过HTTP POST 方法发给控制器.

$ curl -X POST -d '{"switch":"00:00:00:00:00:00:00:01", "name":"flow-mod-1", "cookie":"0", "priority":"32768", "in_port":"1","active":"true", "actions":"output=2"}'  http://<controller_ip>:8080/wm/staticentrypusher/json

Adding a group

和添加一个流表项很相似,注意要有entry_type,如下:

curl -X POST -d '{"switch":"00:00:00:00:00:00:00:01", "entry_type":"group", "name":"group-mod-1", "active":"true", "group_type":"select", "group_id":"1",  "group_buckets":[ {"bucket_id":"1", "bucket_watch_group":"any", "bucket_weight":"50", "bucket_actions":"output=2"}, {"bucket_id":"2", "bucket_watch_group":"any", "bucket_weight":"50", "bucket_actions":"output=3"} ]}' http://<controller_ip>:8080/wm/staticentrypusher/json

清空流表项

curl http://<controller_ip>:8080/wm/staticentrypusher/clear/00:00:00:00:00:00:00:01/json
curl http://<controller_ip>:8080/wm/staticentrypusher/clear/all/json

删除流表项

curl -X DELETE -d '{"name":"flow-mod-1"}' http://<controller_ip>:8080/wm/staticentrypusher/json

一个Entry的组成

流表项和组表项的组成是不同的:

先看看他们共同的部分

  • 必须要有的属性
    |Key|value|notes|
    |name|string|name of the entry|
    |switch|dp id|switch的id|
    |entry_type|string|默认是flow,goup标明是组表|

  • 可选的属性
    |Key|Value|Notes|
    |active|boolean|”true\false”|

  • 预订端口关键字
    ||notes|
    |all|全部端口|
    |contrnller|controller的端口|
    |flood|除了入口和被禁止flood的其他端口|
    |in_port|数据包的入口|
    |local|交换机本地网络堆栈,如 to/from switch OS|
    |normal|使用switch 正常的pipeline处理|
    |any|all switch port注意和all不同,是单数,即任意一个|

  • 约定的组表关键字
    | 预订的组 | notes |
    | all | 全部的交换机组 |
    | any | 任意的交换机组 |

  • 其他还有很多内容,下期在详细学习
    静态entry