forked from floodlight/floodlight
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
313 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/net/floodlightcontroller/statistics/FTGuardManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.floodlightcontroller.statistics; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.projectfloodlight.openflow.types.DatapathId; | ||
import org.projectfloodlight.openflow.types.IPv4Address; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class FTGuardManager { | ||
private static final Logger log = LoggerFactory.getLogger(FTGuardManager.class); | ||
public boolean flag; | ||
|
||
public FTGuardManager() { | ||
this.flag = false; | ||
} | ||
|
||
public void init() { | ||
// add switch to ft-guard | ||
DatapathId id = DatapathId.of("00:00:00:00:00:00:00:01"); | ||
this.addDatapath(id); | ||
this.addHost(IPv4Address.of("10.0.0.1"), id); | ||
this.addHost(IPv4Address.of("10.0.0.2"), id); | ||
this.addHost(IPv4Address.of("10.0.0.3"), id); | ||
this.addHost(IPv4Address.of("10.0.0.10"), id); | ||
initScore(); | ||
this.flag = true; | ||
} | ||
|
||
private void initScore() { | ||
if (flag) return; | ||
StatisticsCollector.scoreImptList.add(2); | ||
StatisticsCollector.scoreImptList.add(6); | ||
StatisticsCollector.scoreImptList.add(9); | ||
|
||
ArrayList<Integer> array1 = new ArrayList<Integer>(); | ||
array1.add(70); array1.add(20); array1.add(10); | ||
ArrayList<Integer> array2 = new ArrayList<Integer>(); | ||
array2.add(10); array2.add(80); array2.add(10); | ||
StatisticsCollector.imptProbMap.put(1, array1); | ||
StatisticsCollector.imptProbMap.put(2, array2); | ||
} | ||
|
||
private void addDatapath(DatapathId id) { | ||
if (flag) return; | ||
log.debug("######ADD-SW-{}", id.toString()); | ||
} | ||
|
||
private void addHost(IPv4Address ip, DatapathId id) { | ||
if (flag) return; | ||
log.debug("######ADD-IP-{}, {}", ip.toString(), id.toString()); | ||
StatisticsCollector.hostDpMap.put(ip, id); | ||
StatisticsCollector.hostFlowMap.put(ip, new HostEntry(ip)); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/net/floodlightcontroller/statistics/HostEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package net.floodlightcontroller.statistics; | ||
|
||
import org.apache.derby.catalog.Statistics; | ||
import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; | ||
import org.projectfloodlight.openflow.protocol.match.Match; | ||
import org.projectfloodlight.openflow.protocol.stat.Stat; | ||
import org.projectfloodlight.openflow.types.DatapathId; | ||
import org.projectfloodlight.openflow.types.IPv4Address; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils.IO; | ||
import com.ziclix.python.sql.util.Queue; | ||
|
||
import io.netty.handler.logging.LogLevel; | ||
import io.netty.util.internal.ThreadLocalRandom; | ||
|
||
public class HostEntry { | ||
private static final Logger log = LoggerFactory.getLogger(HostEntry.class); | ||
private int number; // Ni | ||
private double score; // Wi | ||
private int highFlowNumber; | ||
private IPv4Address ip; | ||
public static int HOST_INIT_FI = 2; | ||
public static int FLOW_MATCH_HIGH_THRESHOLD = 2; | ||
public static int CONSTANT_T = 2; | ||
public int importance; | ||
|
||
public HostEntry(IPv4Address ipAddress) { | ||
number = 0; | ||
highFlowNumber = 0; | ||
ip = ipAddress; | ||
importance = 2; | ||
score = 0; | ||
} | ||
|
||
public void init() { | ||
number = 0; | ||
highFlowNumber = 0; | ||
importance = 2; | ||
score = 0; | ||
} | ||
|
||
public void setScore(double s) { | ||
score = s; | ||
} | ||
public String toString() { | ||
return String.valueOf((int)score) + " - " + String.valueOf(importance); | ||
} | ||
public int getHighFlowNumber() { | ||
return highFlowNumber; | ||
} | ||
public int getNumber() { | ||
return number; | ||
} | ||
public double getScore() { | ||
return score; | ||
} | ||
|
||
public void compute() { | ||
if (number == 0) score = 0.000001; | ||
else | ||
score = (double)highFlowNumber / number; | ||
score *= 10; | ||
int impt = 1; | ||
int temp = (int)score; | ||
for (int i : StatisticsCollector.scoreImptList) { | ||
if (i > temp) break; | ||
impt += 1; | ||
} | ||
importance = impt; | ||
} | ||
|
||
// public void compute() { | ||
// if (number == 0) score = 0.000001; | ||
// else | ||
// score = (double)highFlowNumber / number; | ||
// score *= 10; | ||
// int impt = 1; | ||
// int temp = (int)score; | ||
// for (int i : StatisticsCollector.scoreImptList) { | ||
// if (i > temp) break; | ||
// impt += 1; | ||
// } | ||
// int randomNum = ThreadLocalRandom.current().nextInt(0, 100); | ||
// if (impt == StatisticsCollector.IMPORTANCE_NUM) importance = impt; | ||
// else { | ||
// int rank = 1; | ||
// for (int i : StatisticsCollector.imptProbMap.get(impt)) { | ||
// randomNum -= i; | ||
// if (randomNum < 0) { | ||
// importance = rank; | ||
// break; | ||
// } | ||
// rank += 1; | ||
// } | ||
// } | ||
// } | ||
|
||
public void udpateByReply(OFFlowStatsEntry pse) { | ||
int packetCount = (int)pse.getPacketCount().getValue(); | ||
number += 1; | ||
if (packetCount > FLOW_MATCH_HIGH_THRESHOLD) { | ||
this.highFlowNumber += 1; | ||
} | ||
} | ||
|
||
public void addEntry(Match match) { | ||
number += 1; | ||
} | ||
} |
Oops, something went wrong.