All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sdnwiselab.sdnwise.loader.SdnWise Maven / Gradle / Ivy

/* 
 * Copyright (C) 2015 SDN-WISE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package com.github.sdnwiselab.sdnwise.loader;

import com.github.sdnwiselab.sdnwise.adaptation.Adaptation;
import com.github.sdnwiselab.sdnwise.adaptation.AdaptationFactory;
import com.github.sdnwiselab.sdnwise.configuration.Configurator;
import com.github.sdnwiselab.sdnwise.controller.Controller;
import com.github.sdnwiselab.sdnwise.controller.ControllerFactory;
import com.github.sdnwiselab.sdnwise.controller.ControllerGui;
import com.github.sdnwiselab.sdnwise.controller.ControllerSocketIo;
import com.github.sdnwiselab.sdnwise.flowvisor.FlowVisor;
import com.github.sdnwiselab.sdnwise.flowvisor.FlowVisorFactory;
import com.github.sdnwiselab.sdnwise.util.NodeAddress;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * SdnWise class of the SDN-WISE project. It loads the configuration file and
 starts the Adaptation, the FlowVisor and the Controller.
 *
 * @author Sebastiano Milardo
 * @version 0.1
 */
public final class SdnWise {

    private FlowVisor flowVisor;
    private Adaptation adaptation;
    private Controller controller;
    
    /**
     * Starts the components of the SDN-WISE Controller. Use the parameter "-c
     * pathToConfigurationFile" to provide a configuration file.
     *
     * @param args the command line arguments
     * @throws java.lang.Exception
     */
    public static void main(String[] args) throws Exception {
            SdnWise sw = new SdnWise();
            sw.startControlPlane("");
    }

    public Adaptation getAdaptation(){
        return adaptation;
    }

    public FlowVisor getFlowVisor() {
        return flowVisor;
    }

    public Controller getController() {
        return controller;
    }
    
    public Controller startController(){
        InputStream configFileURI = this.getClass().getResourceAsStream("/config.ini");
        Configurator conf = Configurator.load(configFileURI);
        controller = ControllerFactory.getController(conf.getController());
        new Thread(controller).start();
        return controller;
    }
    
    public Controller startController(String configFilePath) {
        InputStream configFileURI = null;
        if (configFilePath == null || configFilePath.equals("")){
            configFileURI = this.getClass().getResourceAsStream("/config.ini");
        } else {
            try {
                configFileURI = new FileInputStream(configFilePath);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(SdnWise.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        Configurator conf = Configurator.load(configFileURI);
        controller = ControllerFactory.getController(conf.getController());
        new Thread(controller).start();
        return controller;
    }
    
    public FlowVisor startFlowVisor(){
        InputStream configFileURI = this.getClass().getResourceAsStream("/config.ini");
        Configurator conf = Configurator.load(configFileURI);
        flowVisor = FlowVisorFactory.getFlowvisor(conf.getFlowvisor());
        new Thread(flowVisor).start();
        return flowVisor;
    }
    
    public FlowVisor startFlowvisor(String configFilePath) {
        InputStream configFileURI = null;
        if (configFilePath == null || configFilePath.equals("")){
            configFileURI = this.getClass().getResourceAsStream("/config.ini");
        } else {
            try {
                configFileURI = new FileInputStream(configFilePath);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(SdnWise.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        Configurator conf = Configurator.load(configFileURI);
        flowVisor = FlowVisorFactory.getFlowvisor(conf.getFlowvisor());
        new Thread(flowVisor).start();
        return flowVisor;
    }
    
    public Adaptation startAdaptation() {
        InputStream configFileURI = this.getClass().getResourceAsStream("/config.ini");
        Configurator conf = Configurator.load(configFileURI);
        adaptation = AdaptationFactory.getAdaptation(conf.getAdaptation());
        new Thread(adaptation).start();
        return adaptation;
    }
    
    public Adaptation startAdaptation(String configFilePath) {
        InputStream configFileURI = null;
        if (configFilePath == null || configFilePath.equals("")){
            configFileURI = this.getClass().getResourceAsStream("/config.ini");
        } else {
            try {
                configFileURI = new FileInputStream(configFilePath);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(SdnWise.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        Configurator conf = Configurator.load(configFileURI);
        adaptation = AdaptationFactory.getAdaptation(conf.getAdaptation());
        new Thread(adaptation).start();
        return adaptation;
    }
    
    public void startControlPlane(String configFilePath){
        controller = startController(configFilePath);
        adaptation = startAdaptation(configFilePath);
        flowVisor = startFlowvisor(configFilePath);
        
        HashSet nodeSetAll = new HashSet<>();
        nodeSetAll.add(new NodeAddress("0.5"));
        nodeSetAll.add(new NodeAddress("0.4"));
        nodeSetAll.add(new NodeAddress("0.3"));
        nodeSetAll.add(new NodeAddress("0.2"));
        nodeSetAll.add(new NodeAddress("0.1"));
        nodeSetAll.add(new NodeAddress("0.0"));
        flowVisor.addController(controller.getId(), nodeSetAll);
        
        ControllerSocketIo io = 
                new ControllerSocketIo(controller, "http://localhost:1337");

        try {
            Thread.sleep(60000);
        } catch (InterruptedException ex) {
            Logger.getLogger(SdnWise.class.getName()).log(Level.SEVERE, null, ex);
        }
        controller.sendFunction(
                (byte) 1,
                new NodeAddress("0.0"), 
                new NodeAddress("0.1"),
                new NodeAddress("0.0"), 
                (byte) 1, 
                "Map.class");
        
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new ControllerGui(controller).setVisible(true);
            }
        });      
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy