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

com.github.sdnwiselab.sdnwise.controller.ControllerStatic 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.controller;

import com.github.sdnwiselab.sdnwise.adapter.Adapter;
import com.github.sdnwiselab.sdnwise.packet.NetworkPacket;
import com.github.sdnwiselab.sdnwise.util.NodeAddress;
import java.util.LinkedList;
import org.graphstream.graph.Node;

/**
 * This class implements the Controller class using a static routing table. When
 * a request from the network is sent, this class sends a SDN_WISE_OPEN_PATH
 * message with the path contained in field results. No action is taken if the
 * topology of the network changes.
 *
 * @author Sebastiano Milardo
 * @version 0.1
 */
public class ControllerStatic extends Controller {

    ControllerStatic(ControllerId id, Adapter lower, NetworkGraph networkGraph) {
        super(id,lower, networkGraph);

        
    }

    public void computeRules(){
        LinkedList path = new LinkedList<>();
        path.add(new NodeAddress("0.0"));
        path.add(new NodeAddress("0.4"));
        path.add(new NodeAddress("0.5"));
        results.put(new NodeAddress("0.5"), path);
    }
    
    
    @Override
    public void manageRoutingRequest(NetworkPacket data) {
        String destination = data.getNetId() + "." + data.getDst();
        String source = data.getNetId() + "." + data.getSrc().toString();
        if (!source.equals(destination)) {
            Node sourceNode = networkGraph.graph.getNode(source);
            Node destinationNode = networkGraph.graph.getNode(destination);

            if (sourceNode != null && destinationNode != null) {
                LinkedList path = results.get(data.getDst());
                if (path != null && path.size() > 1) {
                    sendPath((byte)data.getNetId(), data.getSrc(), path);
                    data.unsetRequestFlag();
                    lower.send(data.toByteArray());
                }
            }
        }
    }

    @Override
    public final void graphUpdate() {

    }

    @Override
    public void setupNetwork() {
        
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy