com.github.sdnwiselab.sdnwise.function.HelloWorld 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.function;
import com.github.sdnwiselab.sdnwise.flowtable.FlowTableEntry;
import com.github.sdnwiselab.sdnwise.packet.NetworkPacket;
import com.github.sdnwiselab.sdnwise.util.Neighbor;
import com.github.sdnwiselab.sdnwise.util.NodeAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.ArrayBlockingQueue;
import org.bouncycastle.util.Strings;
/**
*
* @author Sebastiano Milardo
*/
public class HelloWorld implements FunctionInterface {
/**
* Implements the function method of FunctionInterface.
* A node can learn new functions that will be executed by using an
* action SDN_WISE_FORWARD_UP and the corresponding ID of the function.
* A function can be installed in a node by using the sendFunction method
* of a controller.
*
* @param adcRegister an HashMap containing measurement info.
* @param flowTable an ArrayList containing the FlowTable of the node.
* @param neighborTable an ArrayList containing the Neighbors table of
* the node.
* @param statusRegister an int[] containing the status of the node.
* @param acceptedId an ArrayList of NodeAddress containing the aliases
* for the address of the node.
* @param messageQueue the incoming message queue. Add a message here in
* order to match it in the FlowTable.
* @param np the NetworkPacket that triggered this function.
*/
@Override
public void function(
HashMap adcRegister,
ArrayList flowTable,
ArrayList neighborTable,
int[] statusRegister,
ArrayList acceptedId,
ArrayBlockingQueue messageQueue,
NetworkPacket np
) {
System.out.println("Hello, World!");
String payload = Strings.fromUTF8ByteArray(np.getPayload());
NodeAddress tmp = np.getDst();
np.setDst(np.getSrc());
np.setSrc(tmp);
np.setPayload(Strings.toUTF8ByteArray(payload.toUpperCase(Locale.ENGLISH)));
messageQueue.add(np.toIntArray());
}
}