Skip to content

Commit

Permalink
Merge branch 'Development'
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenmunilla committed Sep 4, 2017
2 parents 0c4c82b + a94f094 commit f1c0d78
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<include name="jython-2.5.2.jar"/>
<include name="libthrift-0.7.0.jar"/>
<include name="commons-io-2.5.jar"/>
<include name="javabuilder.jar"/>
<include name="wi5.jar"/>
</patternset>

<path id="classpath">
Expand Down
Binary file added lib/javabuilder.jar
Binary file not shown.
Binary file added lib/wi5.jar
Binary file not shown.
16 changes: 14 additions & 2 deletions poolfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ NETWORKS wi5-demo
# APPLICATION net.floodlightcontroller.odin.applications.FlowDetectionManager
# DETECTION 192.168.1.200

####### ShowStatistics
# APPLICATION net.floodlightcontroller.odin.applications.ShowStatistics

####### MobilityManager params
Expand All @@ -22,11 +23,22 @@ NETWORKS wi5-demo
# APPLICATION net.floodlightcontroller.odin.applications.ShowScannedStationsStatistics
# INTERFERENCES 30 30 5 1 ScannedStationsStatistics.txt


####### ShowMatrixOfDistancedBs params
####### MATRIX TimeToStart(seg) ReportingPeriod(seg) ScanningInterval(seg) AddedTime(seg) Channel
# APPLICATION net.floodlightcontroller.odin.applications.ShowMatrixOfDistancedBs
# MATRIX 30 30 5 1 6
# MATRIX 30 30 2 1 6

####### ChannelAssignment params
####### CHANNEL TimeToStart(seg) Period(seg) ScanningInterval(seg) AddedTime(seg) Channel Method
####### Method = 1 : Wi5, 2 : RANDOM, 3 : LCC ;
# APPLICATION net.floodlightcontroller.odin.applications.ChannelAssignment
# CHANNEL 30 30 2 1 6 1

####### Interactive (prompt-based) application, which allows the user to introduce a channel number for each AP throught the keyboard
# APPLICATION net.floodlightcontroller.odin.applications.ChannelPrompt

####### Continuous loop (10 sec) between the 11 channels of 2.4 GHz. The application moves an AP between all the channels
# APPLICATION net.floodlightcontroller.odin.applications.ChannelLoop

# Pool-2
#NAME pool-2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
package net.floodlightcontroller.odin.applications;

import java.net.InetAddress;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.io.*;

import net.floodlightcontroller.odin.master.OdinApplication;
import net.floodlightcontroller.odin.master.OdinClient;
import net.floodlightcontroller.util.MACAddress;

import net.floodlightcontroller.odin.master.OdinMaster.ChannelAssignmentParams;

import org.apache.commons.io.output.TeeOutputStream;

import com.mathworks.toolbox.javabuilder.*;
import wi5.*;

public class ChannelAssignment extends OdinApplication {

// IMPORTANT: this application only works if all the agents in the
//poolfile are activated before the end of the INITIAL_INTERVAL.
// Otherwise, the application looks for an object that does not exist
//and gets stopped

// SSID to scan
private final String SCANNED_SSID = "odin_init";

// Scann params
private ChannelAssignmentParams CHANNEL_PARAMS;

// Scanning agents
Map<InetAddress, Integer> scanningAgents = new HashMap<InetAddress, Integer> ();
int result; // Result for scanning

// Matrix
private String matrix = "";
private String avg_dB = "";

// Algorithm results

private int[][] channels = null;

@Override
public void run() {

this.CHANNEL_PARAMS = getChannelAssignmentParams();
try {
Thread.sleep(CHANNEL_PARAMS.time_to_start);
} catch (InterruptedException e) {
e.printStackTrace();
}

while (true) {
try {
Thread.sleep(CHANNEL_PARAMS.period);
matrix = "";

boolean isValidforChAssign = true;
int numAPs = getAgents().size();
double[][] pathLosses = new double[numAPs][numAPs];
int row = 0, column = 0;

System.out.println("[ChannelAssignment] Matrix of Distance");
System.out.println("[ChannelAssignment] ==================");
System.out.println("[ChannelAssignment]");

//For channel SCANNING_CHANNEL
System.out.println("[ChannelAssignment] Scanning channel " + CHANNEL_PARAMS.channel);
System.out.println("[ChannelAssignment]");

for (InetAddress beaconAgentAddr: getAgents()) {
scanningAgents.clear();
System.out.println("[ChannelAssignment] Agent to send measurement beacon: " + beaconAgentAddr);

// For each Agent
System.out.println("[ChannelAssignment] Request for scanning during the interval of " + CHANNEL_PARAMS.scanning_interval + " ms in SSID " + SCANNED_SSID);
for (InetAddress agentAddr: getAgents()) {
if (agentAddr != beaconAgentAddr) {
System.out.println("[ChannelAssignment] Agent: " + agentAddr);

// Request distances
result = requestScannedStationsStatsFromAgent(agentAddr, CHANNEL_PARAMS.channel, SCANNED_SSID);
scanningAgents.put(agentAddr, result);
}
}

// Request to send measurement beacon
if (requestSendMesurementBeaconFromAgent(beaconAgentAddr, CHANNEL_PARAMS.channel, SCANNED_SSID) == 0) {
System.out.println("[ChannelAssignment] Agent BUSY during measurement beacon operation");
isValidforChAssign = false;
continue;
}

try {
Thread.sleep(CHANNEL_PARAMS.scanning_interval + CHANNEL_PARAMS.added_time);
}
catch (InterruptedException e) {
e.printStackTrace();
}

// Stop sending meesurement beacon
stopSendMesurementBeaconFromAgent(beaconAgentAddr);

matrix = matrix + beaconAgentAddr.toString().substring(1);

for (InetAddress agentAddr: getAgents()) {
if (agentAddr != beaconAgentAddr) {

System.out.println("[ChannelAssignment]");
System.out.println("[ChannelAssignment] Agent: " + agentAddr + " in channel " + CHANNEL_PARAMS.channel);

// Reception distances
if (scanningAgents.get(agentAddr) == 0) {
System.out.println("[ChannelAssignment] Agent BUSY during scanning operation");
isValidforChAssign = false;
continue;
}
Map<MACAddress, Map<String, String>> vals_rx = getScannedStationsStatsFromAgent(agentAddr,SCANNED_SSID);

// for each STA scanned by the Agent
for (Entry<MACAddress, Map<String, String>> vals_entry_rx: vals_rx.entrySet()) {
// NOTE: the clients currently scanned MAY NOT be the same as the clients who have been associated
MACAddress APHwAddr = vals_entry_rx.getKey();
avg_dB = vals_entry_rx.getValue().get("avg_signal");
System.out.println("\tAP MAC: " + APHwAddr);
System.out.println("\tavg signal: " + avg_dB + " dBm");
if(avg_dB.length()>6){
matrix = matrix + "\t" + avg_dB.substring(0,6) + " dBm";
}else{
matrix = matrix + "\t" + avg_dB + " dBm ";
}

boolean isMultiple = false;
if(!isMultiple) {
pathLosses[row][column] = Double.parseDouble(avg_dB);
if(++column >= numAPs) {
column = 0;
row ++;
}
isMultiple = true;
}
else
{
isValidforChAssign = false;
System.out.println("[ChannelAssignment] ===================================");
System.out.println("[ChannelAssignment] ERROR");
System.out.println("[ChannelAssignment] ===================================");
}
}

}else{
matrix = matrix + "\t----------";
pathLosses[row][column] = 0;
if(++column >= numAPs) {
column = 0;
row ++;
}
}
}
matrix = matrix + "\n";
}
//Print matrix
System.out.println("[ChannelAssignment] === MATRIX OF DISTANCES (dBs) ===\n");
System.out.println(matrix);
System.out.println("[ChannelAssignment] =================================");

/*System.out.println("============PATH LOSS START=============");
for(int i=0;i<numAPs; i++) {
System.out.println(Arrays.toString(pathLosses[i]));
}
System.out.println("============PATH LOSS END=============");*/

// End of loop for iteration, as result, a moving mean of the matrix

if(isValidforChAssign) {
channels = this.getChannelAssignments(pathLosses, CHANNEL_PARAMS.method); // Method: 1 for WI5, 2 for RANDOM, 3 for LCC
int i=0;
for (InetAddress agentAddr: getAgents()) {
System.out.println("[ChannelAssignment] Setting AP " + agentAddr + " to channel: " + channels[0][i]);
setChannelToAgent(agentAddr,channels[0][i]);
i++;
}
}else{
System.out.println("[ChannelAssignment] Matrix not valid for channel assignment");
}
System.out.println("[ChannelAssignment] =================================");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

private int[][] getChannelAssignments(double[][] pathLosses, int methodType) {

//System.out.println(System.getProperty("java.library.path"));

MWNumericArray n = null; /* Stores method_number */
Object[] result = null; /* Stores the result */
Wi5 channelFinder= null; /* Stores magic class instance */

MWNumericArray pathLossMatrix = null;

MWNumericArray channelsArray = null;
int[][] channels = null;

try
{ /* Convert and print inputs */
pathLossMatrix = new MWNumericArray(pathLosses, MWClassID.DOUBLE);
n = new MWNumericArray(methodType, MWClassID.DOUBLE);
/* Create new ChannelAssignment object */

channelFinder = new Wi5();
result = channelFinder.getChannelAssignments(1, pathLossMatrix, n);

/* Compute magic square and print result */
System.out.println("[ChannelAssignment] =======CHANNEL ASSIGNMENTS=======");
System.out.println(result[0]); // result is type Object
System.out.println("[ChannelAssignment] =================================");

channelsArray = (MWNumericArray) result[0]; // Object to 2D MWNumericArray
channels = (int[][]) channelsArray.toIntArray(); // 2D MWNumericArray to int[][]
}
catch (Exception e)
{
System.out.println("Exception: " + e.toString());
}

finally
{
/* Free native resources */
MWArray.disposeArray(pathLossMatrix);
MWArray.disposeArray(result);
MWArray.disposeArray(channelsArray);
if (channelFinder != null)
channelFinder.dispose();
return channels;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package net.floodlightcontroller.odin.applications;

import java.net.InetAddress;
import java.util.Arrays;
import java.util.Set;
import java.util.Scanner;
import java.io.*;

import net.floodlightcontroller.odin.master.OdinApplication;
import net.floodlightcontroller.odin.master.OdinClient;

public class ChannelLoop extends OdinApplication {

// IMPORTANT: this application only works if all the agents in the
//poolfile are activated before 15 seconds.
// Otherwise, the application looks for an object that does not exist
//and gets stopped

private InetAddress apAddr;

private Scanner in = new Scanner(System.in);

@Override
public void run() {

try {
Thread.sleep(15000); // Wait 15 seconds to start
} catch (InterruptedException e) {
e.printStackTrace();
}

for (InetAddress agentAddr: getAgents()) { // First Ap in poolfile
apAddr = agentAddr;
System.out.println("[ChannelAssignment] AP: " + apAddr );
break;
}

System.out.println("Press \"ENTER\" to change to channel 1..."); //
in.nextLine();
setChannelToAgent(apAddr,1); // Change channel to 1

System.out.println("Press \"ENTER\" to begin channel iteration...");
in.nextLine();
int i=1;
while(i<=11){
System.out.println("[ChannelAssignment] New channel for AP " + apAddr + ": " + i);
setChannelToAgent(apAddr,i);
try{
Thread.sleep(10000);
}catch(InterruptedException e) {
e.printStackTrace();
}
if(i==11){
i=1;
}else{
i++;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.floodlightcontroller.odin.applications;

import java.net.InetAddress;
import java.util.Arrays;
import java.util.Set;
import java.util.Scanner;
import java.io.*;

import net.floodlightcontroller.odin.master.OdinApplication;
import net.floodlightcontroller.odin.master.OdinClient;

public class ChannelPrompt extends OdinApplication {

// IMPORTANT: this application only works if all the agents in the
//poolfile are activated before 15 seconds.
// Otherwise, the application looks for an object that does not exist
//and gets stopped

private InetAddress apAddr;
private int channel;

private Scanner in = new Scanner(System.in);

@Override
public void run() {

try {
Thread.sleep(15000); // Wait 15 seconds to start
} catch (InterruptedException e) {
e.printStackTrace();
}

while(true){
for (InetAddress agentAddr: getAgents()) {
apAddr = agentAddr;
channel = getChannelFromAgent(apAddr);
System.out.println("[ChannelAssignment] AP " + apAddr + " in channel: " + channel);
System.out.print("[ChannelAssignment] Select channel for AP " + apAddr + ":");
channel = in.nextInt();
setChannelToAgent(apAddr,channel);
}
}
}
}
Loading

0 comments on commit f1c0d78

Please sign in to comment.