Commit 76dad701 authored by ymwang's avatar ymwang

动态网络拓扑下发

parent a86f0292
...@@ -9,83 +9,71 @@ import java.io.File; ...@@ -9,83 +9,71 @@ import java.io.File;
import java.util.*; import java.util.*;
public class CycleTopoUnit { public class CycleTopoUnit {
public static void main(String[] args) { public static void main(String[] args) throws IllegalAccessException{
cycleTpE(); cycleTp();
} }
public static HashMap<Integer, double[][]> cycleTpE(){ public static HashMap<Integer, int[][]> cycleTp() {
//从文本中获取卫星的数据 //从文本中获取卫星的数据
WeixingImpl wx = new WeixingImpl(); WeixingImpl wx = new WeixingImpl();
ToponetImpl tp = new ToponetImpl(); ToponetImpl tp = new ToponetImpl();
SimData sd = new SimData(); SimData sd = new SimData();
//tp.delHistory(); //tp.delHistory();
File file = new File("D:\\project\\topusim_1.txt"); File file = new File("F:\\ymwang\\topusim_1.txt");
//D:\LabratoryJavaPro\codingDownload\latestCoding\
List<WeiXingData> wxData = null; List<WeiXingData> wxData = null;
{ try {
try { wxData = wx.iniTopo(file,sd.getZhouqi());
wxData = wx.iniTopo(file,sd.getZhouqi()); } catch (IllegalAccessException e) {
} catch (IllegalAccessException e) { e.printStackTrace();
e.printStackTrace();
}
} }
//初始topo
int[][] toponet = tp.getTopology(wxData,sd);
//去掉ovs sd.setJiange(60);
double[][] topoNet = new double[6][6]; //卫星节点数目 卫星组成的网络拓扑 sd.setC0(3e10);
for (int i = 0;i<topoNet.length;i++){
for (int j = 0;j<topoNet.length;j++){
topoNet[i][j] = toponet[i][j];
}
}
HashMap<Integer, double[][]> TopoStore = new HashMap<>();
TopoStore.put(0,topoNet);
for (int i = 1;i<sd.getZhouqi()/sd.getJiange(); i++) { //存储全周期拓扑
HashMap<Integer, int[][]> TopoStore = new HashMap<>();
out:for (int i = 0; i<sd.getZhouqi()/sd.getJiange(); i++) {
//Thread.sleep(2000);
int time = i * sd.getJiange(); int time = i * sd.getJiange();
List<WeiXingData> changetp = wx.changeTopo(wxData,time); List<WeiXingData> changetp = wx.changeTopo(wxData,time);
int[][] changeTopo = tp.getTopology(changetp,sd);
//去掉ovs int[][] topoChange = tp.getTopology(changetp,sd);
for (int k = 0;k<topoNet.length;k++){
for (int j = 0;j<topoNet.length;j++){ TopoStore.put(i,topoChange);
topoNet[k][j] = changeTopo[k][j];
}
}
for (int k = 0;k<topoNet.length;k++){
for (int j = k+1;j<topoNet.length;j++){
topoNet[k][j] = topoNet[j][k];
}
}
TopoStore.put(i,topoNet);
} }
/*
* 对比全周期拓扑
* count记录重复拓扑行数
* count2记录不同拓扑数目
* */
int count = 0; int count = 0;
int count2 = -1; int count2 = 0;
Iterator<Map.Entry<Integer, double[][]>> iterator = TopoStore.entrySet().iterator(); Iterator<Map.Entry<Integer, int[][]>> iterator = TopoStore.entrySet().iterator();
while(iterator.hasNext()){ while (iterator.hasNext()){
double[][] value = iterator.next().getValue(); int[][] value = iterator.next().getValue();
for (int i = 0;i<value.length;i++){ System.out.println(Arrays.deepToString(value));
if (i>0){ System.out.println("=========================================");
boolean equals = Arrays.equals(value[i], topoNet[i]); System.out.println(count2);
while (iterator.hasNext()){
int[][] valueNext = iterator.next().getValue();
for (int i = 0;i<value.length;i++){
boolean equals = Arrays.equals(value[i], valueNext[i]);
count += (equals?1:0); count += (equals?1:0);
} }
for (int j = 0;j<topoNet.length;j++){
topoNet[i][j] = value[i][j];
}
}
for (int k = 0;k<topoNet.length;k++){
for (int j = k+1;j<topoNet.length;j++){
topoNet[k][j] = topoNet[j][k];
}
if (count != 30){
System.out.println(Arrays.deepToString(valueNext));
System.out.println("=========================================");
System.out.println(count2);
count2++;
}
count=0;
value=valueNext;
} }
if (count != 30){
count2++;
}
System.out.println(Arrays.deepToString(topoNet));
System.out.println("=========================================");
System.out.println(count2);
} }
return TopoStore; return TopoStore;
} }
} }
...@@ -6,7 +6,7 @@ import java.util.HashMap; ...@@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Stack; import java.util.Stack;
import static top.ninwoo.weixingsim.dynamicNet.CycleTopoUnit.cycleTpE; import static top.ninwoo.weixingsim.dynamicNet.CycleTopo.cycleTp;
/** /**
...@@ -146,8 +146,8 @@ public class DoMap { ...@@ -146,8 +146,8 @@ public class DoMap {
} }
int slotKey = (int) ((((System.currentTimeMillis()-time)/20/1000)-1)%300+1); int slotKey = (int) ((((System.currentTimeMillis()-time)/20/1000)-1)%300+1);
startT= ((System.currentTimeMillis()-time)/20000+1)*20000; startT= ((System.currentTimeMillis()-time)/20000+1)*20000;
//HashMap<Integer, double[][]> cycleTp = cycleTp(); HashMap<Integer, double[][]> cycleTp = cycleTp();
HashMap<Integer, double[][]> cycleTp = cycleTpE(); //HashMap<Integer, double[][]> cycleTp = cycleTpE();
//获得单时隙连接矩阵 0或MAXWEIGHT //获得单时隙连接矩阵 0或MAXWEIGHT
......
...@@ -6,7 +6,7 @@ import java.util.HashMap; ...@@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Stack; import java.util.Stack;
import static top.ninwoo.weixingsim.dynamicNet.CycleTopoUnit.cycleTpE; import static top.ninwoo.weixingsim.dynamicNet.CycleTopoUnit.cycleTp;
public class TimeExpanGraph { public class TimeExpanGraph {
...@@ -38,7 +38,7 @@ public class TimeExpanGraph { ...@@ -38,7 +38,7 @@ public class TimeExpanGraph {
dev = num * slotnum;//10个卫星节点,3个时隙,则共有10*3个卫星节点 dev = num * slotnum;//10个卫星节点,3个时隙,则共有10*3个卫星节点
//组装最短路矩阵 //组装最短路矩阵
double[][] matrixGraph = MatrixGraph(); int[][] matrixGraph = MatrixGraph();
System.out.println("大矩阵是:"); System.out.println("大矩阵是:");
for (int i = 0; i < matrixGraph.length; i++) { for (int i = 0; i < matrixGraph.length; i++) {
for (int j = 0; j < matrixGraph[0].length; j++) { for (int j = 0; j < matrixGraph[0].length; j++) {
...@@ -52,7 +52,7 @@ public class TimeExpanGraph { ...@@ -52,7 +52,7 @@ public class TimeExpanGraph {
} }
} }
private static double[][] MatrixGraph() { private static int[][] MatrixGraph() {
//获取当前3时隙拓扑 //获取当前3时隙拓扑
/** /**
...@@ -70,11 +70,11 @@ public class TimeExpanGraph { ...@@ -70,11 +70,11 @@ public class TimeExpanGraph {
int slotKey = (int) ((((System.currentTimeMillis()-time)/20/1000)-1)%300+1); int slotKey = (int) ((((System.currentTimeMillis()-time)/20/1000)-1)%300+1);
startT= ((System.currentTimeMillis()-time)/20000+1)*20000; startT= ((System.currentTimeMillis()-time)/20000+1)*20000;
HashMap<Integer, double[][]> cycleTp = cycleTpE(); HashMap<Integer,int[][]> cycleTp = cycleTp();
//获得第1个时隙的连接矩阵 0或1 //获得第1个时隙的连接矩阵 0或1
double[][] currentTp = cycleTp.get((slotKey)%300+1); int[][] currentTp = cycleTp.get((slotKey)%300+1);
double[][] slot1 = new double[num][num]; //10*10的矩阵图 int[][] slot1 = new int[num][num]; //10*10的矩阵图
for(int i = 0;i<slot1.length;i++){ for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1[0].length;j++){ for(int j = 0;j<slot1[0].length;j++){
slot1[i][j] = currentTp[i][j]; slot1[i][j] = currentTp[i][j];
...@@ -96,12 +96,12 @@ public class TimeExpanGraph { ...@@ -96,12 +96,12 @@ public class TimeExpanGraph {
//获得第2个时隙的连接矩阵 //获得第2个时隙的连接矩阵
currentTp = cycleTp.get((slotKey)%300+2); currentTp = cycleTp.get((slotKey)%300+2);
double[][] slot2 = new double[num][num]; int[][] slot2 = new int[num][num];
for(int i = 0;i<slot2.length;i++){ for(int i = 0;i<slot2.length;i++){
for(int j = 0;j<slot2.length;j++){ for(int j = 0;j<slot2.length;j++){
if (currentTp[i][j]==0){ if (currentTp[i][j]==0){
if (i==j){ if (i==j){
slot2[i][j]=0.0; slot2[i][j]=0;
}else }else
slot2[i][j] = 0; slot2[i][j] = 0;
}else { }else {
...@@ -112,12 +112,12 @@ public class TimeExpanGraph { ...@@ -112,12 +112,12 @@ public class TimeExpanGraph {
//获得第3个时隙的连接矩阵 //获得第3个时隙的连接矩阵
currentTp = cycleTp.get((slotKey)%300+3); currentTp = cycleTp.get((slotKey)%300+3);
double[][] slot3 = new double[num][num]; int[][] slot3 = new int[num][num];
for(int i = 0;i<slot3.length;i++){ for(int i = 0;i<slot3.length;i++){
for(int j = 0;j<slot3.length;j++){ for(int j = 0;j<slot3.length;j++){
if (currentTp[i][j]==0){ if (currentTp[i][j]==0){
if (i==j){ if (i==j){
slot3[i][j]=0.0; slot3[i][j]=0;
}else }else
slot3[i][j] = 0; slot3[i][j] = 0;
}else { }else {
...@@ -126,7 +126,7 @@ public class TimeExpanGraph { ...@@ -126,7 +126,7 @@ public class TimeExpanGraph {
} }
} }
//生成相邻时隙矩阵 //生成相邻时隙矩阵
double[][] neighbor = new double[num][num]; int[][] neighbor = new int[num][num];
for(int i = 0;i<neighbor.length;i++){ for(int i = 0;i<neighbor.length;i++){
for(int j = 0;j<neighbor.length;j++){ for(int j = 0;j<neighbor.length;j++){
if(i == j){ if(i == j){
...@@ -137,14 +137,14 @@ public class TimeExpanGraph { ...@@ -137,14 +137,14 @@ public class TimeExpanGraph {
} }
} }
//生成其余时隙矩阵 //生成其余时隙矩阵
double[][] nonNeighbor = new double[num][num]; int[][] nonNeighbor = new int[num][num];
for(int i = 0;i<nonNeighbor.length;i++){ for(int i = 0;i<nonNeighbor.length;i++){
for(int j = 0;j<nonNeighbor.length;j++){ for(int j = 0;j<nonNeighbor.length;j++){
nonNeighbor[i][j] = 0; nonNeighbor[i][j] = 0;
} }
} }
//组装连接矩阵 //组装连接矩阵
double[][] edgeWeight = new double[dev][dev]; int[][] edgeWeight = new int[dev][dev];
for(int i = 0;i<edgeWeight.length;i++){ for(int i = 0;i<edgeWeight.length;i++){
for(int j = 0;j<edgeWeight[0].length;j++){ for(int j = 0;j<edgeWeight[0].length;j++){
if (i>=0 & i<num & j>=0 & j<num) { if (i>=0 & i<num & j>=0 & j<num) {
......
package top.ninwoo.weixingsim.sateTopology;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WxMain {
public static void main(String[] args) {
SpringApplication.run(WxMain.class, args);
/*try {
new Initapp().run();
} catch (Exception e) {
e.printStackTrace();
}*/
}
}
...@@ -2,6 +2,7 @@ package top.ninwoo.weixingsim.sateTopology.init; ...@@ -2,6 +2,7 @@ package top.ninwoo.weixingsim.sateTopology.init;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import top.ninwoo.bishe.starter.service.ClusterService; import top.ninwoo.bishe.starter.service.ClusterService;
import top.ninwoo.common.entity.*; import top.ninwoo.common.entity.*;
import top.ninwoo.weixingsim.sateTopology.entity.SimData; import top.ninwoo.weixingsim.sateTopology.entity.SimData;
...@@ -26,9 +27,9 @@ public class Initapp implements CommandLineRunner { ...@@ -26,9 +27,9 @@ public class Initapp implements CommandLineRunner {
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig(); SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
List<ContainerDescription> cds = new ArrayList<>(); List<ContainerDescription> cds = new ArrayList<>();
// TODO: 这个ID应该是从借口获取的 // TODO: 这个ID应该是从借口获取的
separatedClusterConfig.setEdgeNodeId("192.168.190.135:18088"); separatedClusterConfig.setEdgeNodeId("192.168.31.198:18088");
ClusterConfig clusterConfig = new ClusterConfig(); ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l); clusterConfig.setId(11111L);
clusterConfig.setOwner("joliu"); clusterConfig.setOwner("joliu");
//从文本中获取卫星的数据 //从文本中获取卫星的数据
...@@ -36,7 +37,8 @@ public class Initapp implements CommandLineRunner { ...@@ -36,7 +37,8 @@ public class Initapp implements CommandLineRunner {
ToponetImpl tp = new ToponetImpl(); ToponetImpl tp = new ToponetImpl();
SimData sd = new SimData(); SimData sd = new SimData();
//tp.delHistory(); //tp.delHistory();
File file = new File("C:\\WorkSpace\\test\\topusim_1.txt"); File file = new File("D:\\LabratoryJavaPro\\codingDownload\\latestCoding\\topusim_1.txt");
List<WeiXingData> wxData = wx.iniTopo(file,sd.getZhouqi()); List<WeiXingData> wxData = wx.iniTopo(file,sd.getZhouqi());
int[][] toponet = tp.getTopology(wxData,sd); int[][] toponet = tp.getTopology(wxData,sd);
......
package top.ninwoo.weixingsim.sateTopology.service; package top.ninwoo.weixingsim.sateTopology.service;
import top.ninwoo.weixingsim.sateTopology.entity.SimData;
import top.ninwoo.weixingsim.sateTopology.entity.WeiXingData; import top.ninwoo.weixingsim.sateTopology.entity.WeiXingData;
import java.io.File; import java.io.File;
......
package top.ninwoo.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import top.ninwoo.bishe.starter.service.ClusterService;
import top.ninwoo.bishe.starter.service.NetworkService;
import top.ninwoo.common.entity.*;
import top.ninwoo.weixingsim.WxMain;
import top.ninwoo.weixingsim.sateTopology.entity.SimData;
import top.ninwoo.weixingsim.sateTopology.entity.WeiXingData;
import top.ninwoo.weixingsim.sateTopology.service.impl.ToponetImpl;
import top.ninwoo.weixingsim.sateTopology.service.impl.WeixingImpl;
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = WxMain.class)
public class TopoTests {
@Autowired
private ClusterService clusterService;
@Resource
private NetworkService networkService;
@Test
public void test3() throws IllegalAccessException, InterruptedException {
ArrayList<SeparatedClusterConfig> clusterConfigs = new ArrayList<>();
SeparatedClusterConfig separatedClusterConfig = new SeparatedClusterConfig();
List<ContainerDescription> cds = new ArrayList<>();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig.setEdgeNodeId("192.168.31.198:18088");
ClusterConfig clusterConfig = new ClusterConfig();
clusterConfig.setId(11111l);
clusterConfig.setOwner("joliu");
//从文本中获取卫星的数据
WeixingImpl wx = new WeixingImpl();
ToponetImpl tp = new ToponetImpl();
SimData sd = new SimData();
//tp.delHistory();
File file = new File("D:\\LabratoryJavaPro\\codingDownload\\latestCoding\\topusim_1.txt");
// D:\LabratoryJavaPro\codingDownload\latestCoding\
List<WeiXingData> wxData = wx.iniTopo(file, sd.getZhouqi());
int[][] toponet = tp.getTopology(wxData, sd);
//创建容器
ContainerDescription containerDescription0 = new ContainerDescription();
containerDescription0.setMode("normal");
containerDescription0.setReplicas(1);
DockerContainer container0 = new DockerContainer();
container0.setName(wxData.get(0).getName());
container0.setCommand("sh");
container0.setImage("joliu/networktest:schedule");
containerDescription0.setDockerContainer(container0);
cds.add(containerDescription0);
for (int k = 1; k < wxData.size(); k++) {
ContainerDescription containerDescription = new ContainerDescription();
containerDescription.setMode("normal");
containerDescription.setReplicas(1);
DockerContainer container = new DockerContainer();
container.setName(wxData.get(k).getName());
container.setCommand("sh");
container.setImage("joliu/networktest:server");
containerDescription.setDockerContainer(container);
cds.add(containerDescription);
}
clusterConfig.setDockers(cds);
NetworkTopology topo = new NetworkTopology();
topo.setAppNames(tp.getAppNames(wxData));
// 这个参数好像没啥用
topo.setTopologyId(11);
topo.setTopology(toponet);
clusterConfig.setTopology(topo);
separatedClusterConfig.setClusterConfig(clusterConfig);
clusterConfigs.add(separatedClusterConfig);
clusterService.sendClusterConfigToEdgeNode(clusterConfigs);
}
}
...@@ -3,7 +3,7 @@ server: ...@@ -3,7 +3,7 @@ server:
zookeeper: zookeeper:
#url: zk.cnf.org:2181 #url: zk.cnf.org:2181
url: 192.168.81.1:2181 url: 192.168.31.190:2181
bs: bs:
...@@ -11,4 +11,4 @@ bs: ...@@ -11,4 +11,4 @@ bs:
name: my-bs-cloud-center name: my-bs-cloud-center
ipservice: ipservice:
#url: ipservice.cnf.org:23333 #url: ipservice.cnf.org:23333
url: 192.168.81.1:23333 url: 192.168.31.190:23333
\ No newline at end of file \ No newline at end of file
...@@ -28,13 +28,13 @@ bs: ...@@ -28,13 +28,13 @@ bs:
ip-prefix: 192 ip-prefix: 192
ipservice: ipservice:
#ip: ipservice.cnf.org:23333 #ip: ipservice.cnf.org:23333
ip: 192.168.81.1:23333 ip: 192.168.31.190:23333
sdn-controller: sdn-controller:
host: sdn.cnf.org host: sdn.cnf.org
port: 6653 port: 6653
zookeeper: zookeeper:
#url: zk.cnf.org:2181 #url: zk.cnf.org:2181
url: 192.168.81.1:2181 url: 192.168.31.190:2181
cnf: cnf:
passwd: Vudo3423 passwd: Vudo3423
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment