com.github.sdnwiselab.sdnwise.controller.ControllerRing Maven / Gradle / Ivy
/*
* Copyright (C) 2015 Seb
*
* 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 static com.github.sdnwiselab.sdnwise.flowtable.FlowTableAction.SDN_WISE_FORWARD_UNICAST;
import com.github.sdnwiselab.sdnwise.flowtable.FlowTableEntry;
import static com.github.sdnwiselab.sdnwise.flowtable.FlowTableWindow.SDN_WISE_EQUAL_OR_LESS;
import static com.github.sdnwiselab.sdnwise.flowtable.FlowTableWindow.SDN_WISE_PACKET;
import static com.github.sdnwiselab.sdnwise.flowtable.FlowTableWindow.SDN_WISE_SIZE_1;
import com.github.sdnwiselab.sdnwise.packet.NetworkPacket;
import static com.github.sdnwiselab.sdnwise.packet.NetworkPacket.SDN_WISE_NXHOP_H;
import static com.github.sdnwiselab.sdnwise.packet.NetworkPacket.SDN_WISE_TYPE;
import com.github.sdnwiselab.sdnwise.packet.ResponsePacket;
/**
*
* @author Seb
*/
public class ControllerRing extends ControllerStatic {
public ControllerRing(ControllerId id, Adapter lower, NetworkGraph networkGraph) {
super(id, lower, networkGraph);
computeRules();
}
@Override
public void manageRoutingRequest(NetworkPacket data) {
if (data.getSrc().intValue() < 3) {
FlowTableEntry rule = new FlowTableEntry();
rule.getWindow()[0]
.setOperator(SDN_WISE_EQUAL_OR_LESS)
.setSize(SDN_WISE_SIZE_1)
.setLocation(SDN_WISE_PACKET)
.setPos(SDN_WISE_TYPE)
.setValueLow(127);
rule.getAction()
.setType(SDN_WISE_FORWARD_UNICAST)
.setLocation(SDN_WISE_PACKET)
.setPos(SDN_WISE_NXHOP_H)
.setValueLow(data.getSrc().getLow() + 1);
ResponsePacket rp = new ResponsePacket(data.getNetId(), data.getSrc(), rule);
this.sendMessage(rp);
} else if (data.getSrc().intValue() == 3) {
FlowTableEntry rule = new FlowTableEntry();
rule.getWindow()[0]
.setOperator(SDN_WISE_EQUAL_OR_LESS)
.setSize(SDN_WISE_SIZE_1)
.setLocation(SDN_WISE_PACKET)
.setPos(SDN_WISE_TYPE)
.setValueLow(127);
rule.getAction()
.setType(SDN_WISE_FORWARD_UNICAST)
.setLocation(SDN_WISE_PACKET)
.setPos(SDN_WISE_NXHOP_H)
.setValueHigh(0)
.setValueLow(0);
ResponsePacket rp = new ResponsePacket(data.getNetId(), data.getSrc(), rule);
this.sendMessage(rp);
}
data.unsetRequestFlag();
this.sendMessage(data);
}
}