SDN开发之基于floodlight控制器做QoS策略

本文介绍了如何在SDN环境中使用floodlight控制器开发QoS策略。通过java代码展示了如何创建和管理QoS策略,并提到了与Ubuntu Console和Python脚本的交互,以及使用REST API开发Web UI。此外,还提及了与OpenFlow协议和OVS的配合使用。
摘要由CSDN通过智能技术生成

SDN开发之基于floodlight控制器做QoS策略



                                                                                             ---温州大学 12网络工程


在floodlight中写主要策略。通过python脚本与ubuntu console界面交互


利用floodlight提供的restAPI开发webUI界面


JAVA部分代码:


package net.floodlightcontroller.qos;



import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.Collection;

import java.util.Collections;

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Properties;


import org.openflow.protocol.OFFlowMod;

import org.openflow.protocol.OFMatch;

import org.openflow.protocol.OFMessage;

import org.openflow.protocol.OFPacketOut;

import org.openflow.protocol.OFPort;

import org.openflow.protocol.OFType;

import org.openflow.protocol.action.OFAction;

import org.openflow.protocol.action.OFActionEnqueue;

import org.openflow.protocol.action.OFActionNetworkTypeOfService;

import org.openflow.protocol.action.OFActionType;

import org.openflow.util.HexString;


import net.floodlightcontroller.core.FloodlightContext;

import net.floodlightcontroller.core.IOFMessageListener;

import net.floodlightcontroller.core.IOFSwitch;

import net.floodlightcontroller.core.module.FloodlightModuleContext;

import net.floodlightcontroller.core.module.FloodlightModuleException;

import net.floodlightcontroller.core.module.IFloodlightModule;

import net.floodlightcontroller.core.module.IFloodlightService;

import net.floodlightcontroller.restserver.IRestApiService;

import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService;

import net.floodlightcontroller.storage.IResultSet;

import net.floodlightcontroller.storage.IStorageSourceService;

import net.floodlightcontroller.storage.StorageException;

import net.floodlightcontroller.qos.QoSPolicy;

import net.floodlightcontroller.qos.QoSTypeOfService;

import net.floodlightcontroller.core.IFloodlightProviderService;


import java.util.ArrayList;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;


public class QoS implements IQoSService, IFloodlightModule,

IOFMessageListener {

protected IFloodlightProviderService floodlightProvider;

protected IStaticFlowEntryPusherService flowPusher;

protected List<QoSPolicy> policies; //Synchronized 

protected List<QoSTypeOfService> services; //Synchronized

protected IRestApiService restApi;

protected FloodlightContext cntx;

protected IStorageSourceService storageSource;

protected Properties props = new Properties();

protected String[] tools;

protected static Logger logger;

protected boolean enabled;

protected String dpidPattern = "^[\\d|\\D][\\d|\\D]:[\\d|\\D][\\d|\\D]:" +

"[\\d|\\D][\\d|\\D]:[\\d|\\D][\\d|\\D]:" +

"[\\d|\\D][\\d|\\D]:[\\d|\\D][\\d|\\D]:" +

"[\\d|\\D][\\d|\\D]:[\\d|\\D][\\d|\\D]$";

public static final String TABLE_NAME = "controller_qos";

public static final String COLUMN_POLID = "policyid";

public static final String COLUMN_NAME = "name";

public static final String COLUMN_MATCH_PROTOCOL = "protocol";

public static final String COLUMN_MATCH_ETHTYPE = "eth-type";

public static final String COLUMN_MATCH_INGRESSPRT = "ingressport";

public static final String COLUMN_MATCH_IPDST = "ipdst";

public static final String COLUMN_MATCH_IPSRC = "ipsrc";

public static final String COLUMN_MATCH_VLANID = "vlanid";

public static final String COLUMN_MATCH_ETHSRC = "ethsrc";

public static final String COLUMN_MATCH_ETHDST = "ethdst";

public static final String COLUMN_MATCH_TCPUDP_SRCPRT = "tcpudpsrcport";

public static final String COLUMN_MATCH_TCPUDP_DSTPRT = "tcpudpdstport";

public static final String COLUMN_NW_TOS = "nw_tos";

public static final String COLUMN_SW = "switches";

public static final String COLUMN_QUEUE = "queue";

public static final String COLUMN_ENQPORT = "equeueport";

public static final String COLUMN_PRIORITY = "priority";

public static final String COLUMN_SERVICE = "service";

public static String ColumnNames[] = { COLUMN_POLID,

COLUMN_NAME,COLUMN_MATCH_PROTOCOL, COLUMN_MATCH_ETHTYPE,COLUMN_MATCH_INGRESSPRT,

COLUMN_MATCH_IPDST,COLUMN_MATCH_IPSRC,COLUMN_MATCH_VLANID,

COLUMN_MATCH_ETHSRC,COLUMN_MATCH_ETHDST,COLUMN_MATCH_TCPUDP_SRCPRT,

COLUMN_MATCH_TCPUDP_DSTPRT,COLUMN_NW_TOS,COLUMN_SW,

COLUMN_QUEUE,COLUMN_ENQPORT,COLUMN_PRIORITY,COLUMN_SERVICE,};

public static final String TOS_TABLE_NAME = "controller_qos_tos";

public static final String COLUMN_SID = "serviceid";

public static final String COLUMN_SNAME = "servicename";

public static final String COLUMN_TOSBITS = "tosbits";

public static String TOSColumnNames[] = {COLUMN_SID,

COLUMN_SNAME,

COLUMN_TOSBITS};

@Override

public String getName() {

return "qos";

}


@Override

public boolean isCallbackOrderingPrereq(OFType type, String name) {

return false;

}


@Override

public boolean isCallbackOrderingPostreq(OFType type, String name) {

        return false;

}


@Override

public Collection<Class<? extends IFloodlightService>> getModuleServices() {

Collection<Class<? extends IFloodlightService>> l = 

                new ArrayList<Class<? extends IFloodlightService>>();

        l.add(IQoSService.class);

        return l;

}


@Override

public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {

Map<Class<? extends IFloodlightService>,

        IFloodlightService> m = 

        new HashMap<Class<? extends IFloodlightService>,

        IFloodlightService>();

        // We are the class that implements the service

        m.put(IQoSService.class, this);

        return m;

}


@Override

public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {

//This module should depend on FloodlightProviderService,

// IStorageSourceProviderService, IRestApiService, &

// IStaticFlowEntryPusherService

Collection<Class<? extends IFloodlightService>> l =

new ArrayList<Class<? extends IFloodlightService>>();

l.add(IFloodlightProviderService.class);

l.add(IStorageSourceService.class);

        l.add(IRestApiService.class);

        l.add(IStaticFlowEntryPusherService.class);

return l;

}

       protected ArrayList<QoSPolicy> readPoliciesFromStorage() {

        ArrayList<QoSPolicy> l = new ArrayList<QoSPolicy>();

        try{

        Map<String, Object> row;


        IResultSet policySet = storageSource

        .executeQuery(TABLE_NAME, ColumnNames, null, null );

        for( Iterator<IResultSet> iter = policySet.iterator(); iter.hasNext();){

        row = iter.next().getRow();

        

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值