Commit 83edb31a authored by Elf's avatar Elf

Merge remote-tracking branch 'origin/path-business' into path-business

# Conflicts:
#	apps/cnf-weixingsim/src/main/java/top/ninwoo/weixingsim/entity/SimData.java
#	apps/cnf-weixingsim/src/test/java/top/ninwoo/WxTests.java
parents 8143f174 26898473
package com.pitong.business.item;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
public class DataPackage implements Serializable {
private int number;
......@@ -12,6 +14,46 @@ public class DataPackage implements Serializable {
private Long currentime;
private Long fun1time;
private List<Double> compCapacity;
private LinkedList<Double> tranDelay;
//当前卫星节点
private int currentHop;
//路由新添解析步骤
private int routeNumber;
public Stack[] route;
public void setTranDelay(LinkedList<Double> tranDelay) {
this.tranDelay = tranDelay;
}
public LinkedList<Double> getTranDelay() {
return tranDelay;
}
public int getCurrentHop() {
return currentHop;
}
public void setCurrentHop(int currentHop) {
this.currentHop = currentHop;
}
public void setRouteNumber(int routeNumber) {
this.routeNumber = routeNumber;
}
public void setRoute(Stack[] route) {
this.route = route;
}
public int getRouteNumber() {
return routeNumber;
}
public Stack[] getRoute() {
return route;
}
public List<Double> getCompCapacity() {
return compCapacity;
......
......@@ -16,9 +16,7 @@ import top.ninwoo.test.doMap.path;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.*;
@SpringBootApplication
@path
......@@ -52,14 +50,38 @@ public class BisheTestMain implements ApplicationRunner {
System.out.println("========================================");
System.out.println("exec start timestamp: " + System.currentTimeMillis());
System.out.println();
System.out.println("launch timestamp: " + System.currentTimeMillis());
System.out.println();
// DoMap doMap = new DoMap();
List<Integer> sequence = Arrays.asList(1, 3, 7, 8, 12, 17, 20);
System.out.println("optimal mapping scheme"+sequence);
DoMap doMap = new DoMap();
doMap.doMapApp();
//将节点映射结果保存为List
int[] result = doMap.result;
while (result[0] == 0){
System.out.println("failure mapping :"+Arrays.toString(result));
doMap.doMapApp();
result = doMap.result;
}
List<Integer> sequence = new ArrayList<>();
for (int a:result
) {
sequence.add(a);
}
//将路由结果保存
Stack[] route = doMap.route;
int routeNumber = 0;
int nextHop = 1;
long waitT = doMap.startT-System.currentTimeMillis();
if (waitT > 0){
Thread.sleep(waitT);
}
System.out.println("exec start timestamp: " + System.currentTimeMillis());
System.out.println("========================================");
System.out.println();
//List<Integer> sequence = Arrays.asList(result);
// System.out.println("optimal mapping scheme"+sequence);
String loc = null;
String file_path = "passport.jpg";
......@@ -70,10 +92,15 @@ public class BisheTestMain implements ApplicationRunner {
List<Double> compCapacity = Arrays.asList(1.112341341313, 0.5196272109574349, 0.675827555541419, 0.7637869915859579, 0.7998320296858645,
0.638652700648973, 0.6396760676518485, 0.5615337810185533, 0.6356797503522186, 0.8266103444996542, 0.6924037701405794,
0.9371892689614395, 0.6949256728585527, 0.6212614126622614, 0.6318393608430264, 0.7494680794385384, 0.9983949989039682,
0.5610722256465777, 0.6415780028672076, 0.9371892689);//取值范围0.2到1,首尾固定为1M/s
DataPackage dataPackage = combine(number, sequence, loc, file_path, eta, currentime, fun1time, compCapacity);
0.5610722256465777, 0.6415780028672076, 0.9371892689, 0.5269659075274151, 0.8219152161388867, 0.5815463889106197, 0.8431429542046349,
0.31386253514456774, 0.6045132365410817, 0.8102279249524735, 0.47057296148341216, 0.8529743685059654, 0.8177711194660409);//取值范围0.2到1,首尾固定为1M/s
LinkedList<Double> tranDelay = doMap.list;
for (int i = 0;i<tranDelay.size();i++){
tranDelay.set(i,tranDelay.get(i)/(i+2)+(Math.random()*10+1));
}
DataPackage dataPackage = combine(number, routeNumber, sequence, loc, file_path, eta, currentime, fun1time, compCapacity,route,nextHop,tranDelay);
send(dataPackage, targetIp, 2020);
//接收卫星回传信息
for(int i = 0;i<sequence.size();i++){
ServerSocket serverSocket = new ServerSocket(8900);
//获取数据流
......@@ -134,15 +161,20 @@ public class BisheTestMain implements ApplicationRunner {
}
}
private static DataPackage combine(int number, List<Integer> sequence, String loc, String file_path, double eta, Long Currentime, Long fun1time, List<Double> compCapacity) {
private static DataPackage combine(int number, int routeNumber, List<Integer> sequence, String loc, String file_path,
double eta, Long Currentime, Long fun1time, List<Double> compCapacity, Stack[] route, int nextHop, LinkedList<Double> tranDelay) {
DataPackage dataPackage = new DataPackage();
dataPackage.setNumber(number);
dataPackage.setRouteNumber(routeNumber);
dataPackage.setPicture(loadPicture(file_path));
dataPackage.setSequence(sequence);
dataPackage.setEta(eta);
dataPackage.setCurrentime(Currentime);
dataPackage.setFun1time(fun1time);
dataPackage.setCompCapacity(compCapacity);
dataPackage.setRoute(route);
dataPackage.setCurrentHop(nextHop);
dataPackage.setTranDelay(tranDelay);
return dataPackage;
}
......
package top.ninwoo.test.doMap;
import top.ninwoo.test.sateTopo.entity.SimData;
import top.ninwoo.test.sateTopo.entity.WeiXingData;
import top.ninwoo.test.sateTopo.service.impl.ToponetImpl;
import top.ninwoo.test.sateTopo.service.impl.WeixingImpl;
import java.io.File;
import java.util.*;
public class CycleTopo {
public static void main(String[] args) { cycleTp(); }
public static HashMap<Integer, double[][]> cycleTp(){
//从文本中获取卫星的数据
WeixingImpl wx = new WeixingImpl();
ToponetImpl tp = new ToponetImpl();
SimData sd = new SimData();
//tp.delHistory();
File file = new File("topusim_1.txt");
//D:\LabratoryJavaPro\codingDownload\latestCoding\
List<WeiXingData> wxData = null;
{
try {
wxData = wx.iniTopo(file,sd.getZhouqi());
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
//初始topo
double[][] toponet = tp.getWeightedTopology(wxData,sd);
//去掉ovs
double[][] topoNet = new double[30][30];
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++) {
int time = i * sd.getJiange();
List<WeiXingData> changetp = wx.changeTopo(wxData,time);
double[][] changeTopo = tp.getWeightedTopology(changetp,sd);
//去掉ovs
for (int k = 0;k<topoNet.length;k++){
for (int j = 0;j<topoNet.length;j++){
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);
}
int count = 0;
int count2 = -1;
Iterator<Map.Entry<Integer, double[][]>> iterator = TopoStore.entrySet().iterator();
while(iterator.hasNext()){
double[][] value = iterator.next().getValue();
for (int i = 0;i<value.length;i++){
if (i>0){
boolean equals = Arrays.equals(value[i], topoNet[i]);
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){
count2++;
}
/* System.out.println(Arrays.deepToString(topoNet));
System.out.println("=========================================");
System.out.println(count2);*/
}
return TopoStore;
}
}
package top.ninwoo.test.doMap;
import top.ninwoo.test.sateTopo.entity.SimData;
import top.ninwoo.test.sateTopo.entity.WeiXingData;
import top.ninwoo.test.sateTopo.service.impl.ToponetImpl;
import top.ninwoo.test.sateTopo.service.impl.WeixingImpl;
import java.io.File;
import java.util.*;
public class CycleTopoUnit {
public static void main(String[] args) { cycleTp(); }
public static HashMap<Integer, int[][]> cycleTp(){
//从文本中获取卫星的数据
WeixingImpl wx = new WeixingImpl();
ToponetImpl tp = new ToponetImpl();
SimData sd = new SimData();
//tp.delHistory();
File file = new File("topusim_1.txt");
//D:\LabratoryJavaPro\codingDownload\latestCoding\
List<WeiXingData> wxData = null;
{
try {
wxData = wx.iniTopo(file,sd.getZhouqi());
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
//初始topo
int[][] toponet = tp.getTopology(wxData,sd);
//去掉ovs
int[][] topoNet = new int[30][30];
for (int i = 0;i<topoNet.length;i++){
for (int j = 0;j<topoNet.length;j++){
topoNet[i][j] = toponet[i][j];
}
}
HashMap<Integer, int[][]> TopoStore = new HashMap<>();
TopoStore.put(0,topoNet);
for (int i = 1;i<sd.getZhouqi()/sd.getJiange(); i++) {
int time = i * sd.getJiange();
List<WeiXingData> changetp = wx.changeTopo(wxData,time);
int[][] changeTopo = tp.getTopology(changetp,sd);
//去掉ovs
for (int k = 0;k<topoNet.length;k++){
for (int j = 0;j<topoNet.length;j++){
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);
}
int count = 0;
int count2 = -1;
Iterator<Map.Entry<Integer, int[][]>> iterator = TopoStore.entrySet().iterator();
while(iterator.hasNext()){
int[][] value = iterator.next().getValue();
for (int i = 0;i<value.length;i++){
if (i>0){
boolean equals = Arrays.equals(value[i], topoNet[i]);
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){
count2++;
}
System.out.println(Arrays.deepToString(topoNet));
System.out.println("=========================================");
System.out.println(count2);
}
return TopoStore;
}
}
package top.ninwoo.test.doMap;
import java.util.Arrays;
import java.util.Random;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import static top.ninwoo.test.doMap.CycleTopo.cycleTp;
/**
......@@ -20,13 +23,13 @@ public class DoMap {
* 业务参数
*/
//数据量MB?
static double D = 5;
static double D = 4;
//子任务数
static int c = 8;
static int c = 7; //8
//子任务依赖关系
static int[][] link = {{0, 1, 1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6, 6, 7}};
//子任务依赖关系
static int[][] link = {{0, 0, 1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 5, 6}};//
//固定映射任务数==起始任务+终止任务
static final int C_STABLE = 2;
......@@ -38,12 +41,13 @@ public class DoMap {
* 网络参数
*/
//设备数
static int num = 20;
static int num = 30;
//设备计算能力参数s GB/s
static double[] nt = {1.112341341313, 0.5196272109574349, 0.675827555541419, 0.7637869915859579, 0.7998320296858645,
0.638652700648973, 0.6396760676518485, 0.5615337810185533, 0.6356797503522186, 0.8266103444996542, 0.6924037701405794,
0.9371892689614395, 0.6949256728585527, 0.6212614126622614, 0.6318393608430264, 0.7494680794385384, 0.9983949989039682,
0.5610722256465777, 0.6415780028672076, 0.9371892689}; //20节点
0.5610722256465777, 0.6415780028672076, 0.9371892689, 0.5269659075274151, 0.8219152161388867, 0.5815463889106197,
0.8431429542046349, 0.31386253514456774, 0.6045132365410817, 0.8102279249524735, 0.47057296148341216, 0.8529743685059654, 0.8177711194660409}; //30节点
//时隙大小
static double slot = 20*1000;
//时隙数目
......@@ -64,7 +68,7 @@ public class DoMap {
* BPSO参数
*/
//粒子群规模
static int n = 200;
static int n = 1000;
//种群迭代次数
static int k = 500;
//惯性权重,加速因子1,2
......@@ -74,17 +78,40 @@ public class DoMap {
doMapApp();
}
//节点最终分配结果
public static int[] result = new int[c];
//节点间最短路由
public static Stack[] route = new Stack[link[0].length+1];
//业务发起时刻
public static long startT;
//传输时延约束
public static LinkedList<Double> list = new LinkedList<>();
public static void doMapApp() {
for (slotnum = 1;slotnum<=3;slotnum++){
//slotnum = 3;
dev = num*slotnum;
n2 = dev - N_STABLE*slotnum;
//组装最短路矩阵
//1组装最短路矩阵
double[][] edgeWeight = WTEG();
//最短路由矩阵
/*System.out.println("DoMap直连边权重");
System.out.println(Arrays.deepToString(edgeWeight));*/
InterSlotDijstraV2 dijs = new InterSlotDijstraV2(num, slot);
InterSlotDijstraV2.pathRecord pathRecord = dijs.dijstra(edgeWeight, testLatency);
//2最短路由矩阵
double[][] lt = pathRecord.pathWeight;
for(int i = 0;i<lt.length;i++){
for(int j = 0;j<lt.length;j++){
lt[i][j] *= D;
}
}
System.out.println("最短路由");
System.out.println(Arrays.deepToString(lt));
for (int i = 0;i<nt.length;i++) {
nt[i] = (D * 1000) / nt[i];
}
......@@ -92,34 +119,147 @@ public class DoMap {
DoMap doMap = new DoMap();
Par best_par = doMap.main_bpso(k, c, dev, n1, n2, D, lt, nt, link, n, s, c1, c2, num, slot, mapdev);
if (best_par.fit != 0){
System.out.println(1 / best_par.fit);
System.out.println(Arrays.toString(best_par.task));
System.out.println(Arrays.toString(best_par.taskfinal));
//System.out.println(1 / best_par.fit);
/* System.out.println(Arrays.toString(best_par.task));
System.out.println(Arrays.toString(best_par.taskfinal));*/
//赋值节点映射结果
int itemp = 0;
for (int a:best_par.taskfinal
) {
result[itemp++] = (a)+1;
//result[itemp++] = (a%num)+1;
}
System.out.println("optimal mapping scheme"+Arrays.toString(result));
//输出最短路由数组
for (int i =0;i<result.length-1;i++){
list.add(lt[result[i]-1][result[i+1]-1]);
}
// System.out.println(list);
//赋值最短路由
//引用类型数组的二次声明
for (int i = 0;i<route.length;i++){
route[i] = new Stack<Integer>();
}
//3根据分配结果,回溯每一条路由
int[][] lastHop = pathRecord.lastHop;
for (int i = 0;i<link[0].length;i++){
int start = best_par.taskfinal[link[0][i]];
int end = best_par.taskfinal[link[1][i]];
while(lastHop[start][end] != 0){
/*if (lastHop[start][end] == start){
}else if(lastHop[start][end] == end){
route[i+1].push((lastHop[start][end])+1);
break;
}else{*/
route[i+1].push((lastHop[start][end])+1);
//route[i+1].push((lastHop[start][end]%num)+1);
end = lastHop[start][end];
}
}
//根据分配结果,回溯每一条路由
System.out.println("--------------------------");
System.out.println("shortest route : ");
//输出最短路由[1, 2, 3, 3, 9, 16, 40]
for (int i = 0;i<route.length-1;i++){
if (route[i+1].empty())
System.out.print(result[link[0][i]]+"-->"+result[link[1][i]]);
else {
System.out.print(result[link[0][i]] + "-->");
Stack<Integer> stack = new Stack<>();
while (!route[i+1].isEmpty()){
int pop = (int) route[i+1].pop();
System.out.print(pop + "-->");
//顺便将数值转换
stack.push((pop-1)%num+1);
}
/*Enumeration items = route[i].elements(); // 得到 stack 中的枚举对象
while (items.hasMoreElements()) //显示枚举(stack ) 中的所有元素
System.out.print(items.nextElement() + "-->");*/
System.out.print(result[link[1][i]]);
while(!stack.isEmpty()){
route[i+1].push(stack.pop());
}
}
System.out.println(); //换行
}
//规范result 和 route 数据
for (int i = 0;i<result.length;i++){
result[i] = ((result[i]-1)%num)+1;
}
//System.out.println(Arrays.toString(result));
break;
}
}
}
//组装大矩阵
private static double[][] WTEG() {
//获取当前3时隙拓扑
/**
* 先用SimpleDateFormat.parse() 方法将日期字符串转化为Date格式
* 通过Date.getTime()方法,将其转化为毫秒数
*/
String date = "2019-01-01 00-00-00";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");//24小时制
long time = 0;
try {
time = simpleDateFormat.parse(date).getTime();
} catch (ParseException e) {
e.printStackTrace();
}
int slotKey = (int) ((((System.currentTimeMillis()-time)/20/1000)-1)%300+1);
startT= ((System.currentTimeMillis()-time)/20000+1)*20000;
HashMap<Integer, double[][]> cycleTp = cycleTp();
//获得单时隙连接矩阵 0或MAXWEIGHT
//等待下一时隙开始执行业务
double[][] currentTp = cycleTp.get((slotKey)%300+1);
double[][] slot1 = new double[num][num];
for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1.length;j++){
slot1[i][j] = 0;
if (currentTp[i][j]==0.0){
if (i==j){
slot1[i][j]=0.0;
}else
slot1[i][j] = MAXWEIGHT;
}else{
slot1[i][j] = 10e5/currentTp[i][j];
}
}
}
// System.out.println(Arrays.deepToString(slot1));
currentTp = cycleTp.get((slotKey++)%300+1);
double[][] slot2 = new double[num][num];
for(int i = 0;i<slot2.length;i++){
for(int j = 0;j<slot2.length;j++){
slot2[i][j] = 0;
if (currentTp[i][j]==0){
if (i==j){
slot2[i][j]=0.0;
}else
slot2[i][j] = MAXWEIGHT;
}else {
slot2[i][j] = 10e5 / currentTp[i][j];
}
}
}
currentTp = cycleTp.get((slotKey++)%300+1);
double[][] slot3 = new double[num][num];
for(int i = 0;i<slot3.length;i++){
for(int j = 0;j<slot3.length;j++){
slot3[i][j] = 0;
if (currentTp[i][j]==0){
if (i==j){
slot3[i][j]=0.0;
}else
slot3[i][j] = MAXWEIGHT;
}else {
slot3[i][j] = 10e5 / currentTp[i][j];
}
}
}
//生成相邻时隙矩阵
......
......@@ -54,14 +54,18 @@ public class InterSlotDijstraV2 {
for(int i = 0; i < edgeWeight.length; i++) {
singlePointDijstra(edgeWeight, i, testLatency, pathRecord.lastHop[i], pathRecord.pathWeight[i]);
/* for(int j = 0; j < edgeWeight.length; j++) {
pathWeight[i][j] = singleRowWeight[j];
// System.out.print(pathWeight[i][j]+""+'\t');
}*/
// System.out.println('\n');
}
System.out.println(Arrays.deepToString(pathRecord.pathWeight));
System.out.println(Arrays.deepToString(pathRecord.lastHop));
// System.out.println(Arrays.deepToString(pathRecord.pathWeight));
//上一跳路由矩阵
/*System.out.println("上一跳路由矩阵");
System.out.println(Arrays.deepToString(pathRecord.lastHop));*/
// System.out.println(Arrays.deepToString(pathWeight));
return pathRecord;
}
......
......@@ -11,17 +11,19 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface path {
String savePath() default "/home/ninwoo/dynamic_sate/picResult";
String savePath() default "/home/ninwoo/jthudocker/picResult";
String rmCmd() default "rm /home/ninwoo/dynamic_sate/picResult/*.jpg";
String rmCmd() default "rm /home/ninwoo/jthudocker/picResult/*.jpg";
String saveCmd1() default "docker cp sate1_0:/pic/in.jpg /home/ninwoo/dynamic_sate/picResult/source.jpg";
String saveCmd1() default "docker cp sate1_0:/pic/in.jpg /home/ninwoo/jthudocker/picResult/source.jpg";
String saveCmd2() default "docker cp sate1_0:/pic/out1.jpg /home/ninwoo/dynamic_sate/picResult/task_1.1.jpg";
String saveCmd2() default "docker cp sate1_0:/pic/out1.jpg /home/ninwoo/jthudocker/picResult/task_1.1.jpg";
String saveCmd3() default "docker cp sate1_0:/pic/out2.jpg /home/ninwoo/dynamic_sate/picResult/task_1.2.jpg";
String saveCmd3() default "docker cp sate1_0:/pic/out2.jpg /home/ninwoo/jthudocker/picResult/task_1.2.jpg";
String saveCmd4() default "_0:/pic/out.jpg /home/ninwoo/dynamic_sate/picResult/task_";
String saveCmd4() default "_0:/pic/out.jpg /home/ninwoo/jthudocker/picResult/task_";
String saveCmd5() default "save pictrues to dynamic_sate/picResult directory finish";
String saveCmd5() default "save pictrues to jthudocker/picResult directory finish";
// /home/ninwoo/jthudocker/picResult /home/ninwoo/dynamic_sate/picResult
}
package top.ninwoo.test.doMap.verification;
import java.util.Arrays;
import java.util.Stack;
public class array2Print {
static Stack[] route = new Stack[8];
static int a;
public static void main(String[] args) {
double[] arr =new double[10];
for (int i = 0;i<10;i++){
arr[i] = Math.random()*0.8+0.2;
}
System.out.println(Arrays.toString(arr));
/*
Stack stack = new Stack();
System.out.println(route[0]);
*/
/* System.out.println(a+1);
for (int i = 0;i<route.length;i++){
route[i] = new Stack();
}*/
/* for (int i = 0;i<8;i++){
stack.push(2);
//route[i].push(2*i);
}*/
//System.out.println(route);
/* int x = 0;
int[][] a = { { 8, 2, 6, 5 }, { 6, 3, 1, 0 }, { 8, 7, 9, 6 } };
System.out.print("\t\t");
for (int i = 0; i <= a.length; i++) {
System.out.print(i + "\t");
}
System.out.print("\n\t" + "-------------------------");
System.out.println();
for (int i = 0; i < a.length; i++) {
System.out.print(i + " |\t");
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + "\t"); // "\t"是制表符
}
System.out.println();
}*/
}
}
package top.ninwoo.test.doMap.verification;
import java.util.LinkedList;
public class tst {
public static void main(String[] args) {
LinkedList<Double> objects = new LinkedList<>();
objects.add((double) 5);
objects.set(0,objects.get(0)/2);
System.out.println(objects);
}
}
package top.ninwoo.test.sateTopo.entity;
import lombok.Data;
/**
* @description 储存有关星间链路的数据
*/
@Data
public class SimData {
//时间间隔,默认值为10
private int jiange = 20;
//周期值,默认值为100分钟,即为6000秒
private int zhouqi = 6000;
//todo:这里因该预设默认值
//星间链路带宽
private double bandwidth = 10e9;
//加性高斯白噪声(AWGN)
private double n0 = 5*10e-15;
//信号发射功率
private double pt = 5*10e3;
//信号发射增益系数
private double gt = 52.5;
//信号接收增益系数
private double gr = 37.5;
//载波波长
private double lamda = 0.05;
//星间信道容量最低容限
private double c0 = 4*10e7;
public double ptGtGr(){
return pt*gt*gr;
}
public double n0B(){
return n0*bandwidth;
}
}
package top.ninwoo.test.sateTopo.entity;
import lombok.Data;
@Data
public class WeiXingData {
//卫星的名字,之后可能作为增删改查的唯一标识
private String name;
//地心距离
private Float high = (float)780;
//根据高度计算得出,规定(默认)逆时针为正方向
private Double speed;
private Boolean tag=true;
//测试用一个角度作为初始相位,后期需要三个角度来算出xyz坐标轴
private Float alpha;
private Float beta;
private Float gamma;
//xyz坐标轴数据
private Double xaxis;
private Double yaxis;
private Double zaxis;
//卫星的序列号
private Integer index;
//运行时间
private Integer lastime = 0;
@Override
public String toString(){
return "卫星名是:"+name+";高度是:"+high+"\n"+"x轴坐标:"+xaxis+"\n"+"y轴坐标:"+yaxis+"\n"+"z轴坐标:"+zaxis;
}
}
package top.ninwoo.test.sateTopo.service;
import top.ninwoo.test.sateTopo.entity.SimData;
import top.ninwoo.test.sateTopo.entity.WeiXingData;
import java.util.List;
/**
* 拓扑网络的服务
* 根据Weixing的服务所得到的List转化为二维数组
*/
public interface Toponet {
/**
* @param weiXingDataList WeiXingData对象
* @return 拓扑图的元素
* @description 得到生成拓扑网络中的所有元素名字,需要自动生成所需的ovs,和docker容器一一对应
*/
String[] getAppNames(List<WeiXingData> weiXingDataList);
/**
* @param weiXingDataList WeiXingData对象
* @return 二维数组,也就是拓扑图
* @description 得到网络拓扑形式类似为 app1 app2 app3 ovs1 ovs2 ovs3
*/
int[][] getTopology(List<WeiXingData> weiXingDataList, SimData simData);
/**
* @param weiXingDataList WeiXingData对象
* @return 二维数组,也就是拓扑图
* @description 得到网络拓扑形式类似为 app1 app2 app3 ovs1 ovs2 ovs3
*/
double[][] getWeightedTopology(List<WeiXingData> weiXingDataList, SimData simData);
/**
* @param a 具体的卫星a
* @param b 具体的卫星b
* @return a,b之间的距离
* @description 计算距离,在getTopology中调用
*/
Double distance(WeiXingData a, WeiXingData b);
Double channelCapacity(WeiXingData a, WeiXingData b, SimData simData);
/**
@description 记录卫星拓扑的变化历史
*/
/**
* @description 写入一个文本文件中,作为拓扑的历史记录
* @param appNames 传入的卫星名字,取前1/2
* @param topo 卫星拓扑图
*/
void history(String[] appNames, int[][] topo);
/**
* @description 删除历史记lu
*/
void delHistory();
}
package top.ninwoo.test.sateTopo.service;
import top.ninwoo.test.sateTopo.entity.WeiXingData;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
* 有关卫星的服务
* 1.解析初始文本,得到初始的卫星状态
* 2.将卫星的状态写入一个List中
* 3.增删改查四种基本功能
*/
public interface Weixing {
/**
* @description 从文本中获取卫星的初始状态,但是其中的数据均为string型
* @param file 传入的文本路径
* @return 返回一个List
*/
List<Map> parseTxt(File file);
/**
* @description 将parseTxt中得到的Map转化为初始的卫星数据
* @param wx WeiXingData类
* @param map parseTxt得到的Map
* @return 单个卫星数据
* @throws IllegalAccessException
*/
WeiXingData initWX(Class wx, Map map)throws IllegalAccessException;
List<WeiXingData> initNet(List<Map> maps) throws IllegalAccessException;
/**
* @description 根据卫星高度计算出卫星的速度,取逆时针为正方向。
* @description 和addAxis不同,只需计算一次即可
* @param wx WeiXingData对象
* @return
*/
List<WeiXingData> addWSpeed(List<WeiXingData> wx, int zhouqi);
/**
* @description 根据角度,高度,速度和间隔时间t获取卫星的坐标数据
* @param wx WeiXingData对象
* @return
*/
List<WeiXingData> addAxis(List<WeiXingData> wx);
/**
* @description 为每个卫星添加序号值
* @param wx 卫星List
* @return bool类型
*/
boolean addIndex(List<WeiXingData> wx);
/**
* @description 确认index和卫星List的对应关系
* @param wx 卫星List
* @return boolean
*/
boolean checkIndex(List<WeiXingData> wx);
/**
* @description 确保卫星列表中中没有名字重复的卫星
* @param wx 卫星List
*/
void checkWX(List<WeiXingData> wx);
/**
增删改查的功能
*/
/**
* @description 根据提供的appName查找对应的序列号
* @param weiXingDataList 卫星List
* @param appName 卫星名字
* @return index 序列号
*/
Integer findindex(List<WeiXingData> weiXingDataList, String appName);
/**
* @description 查找功能
* @param weiXingDataList 传入的卫星列表
* @param appName 查找的卫星名字
* @return 卫星数据
*/
WeiXingData findWX(List<WeiXingData> weiXingDataList, String appName);
/**
* @description 增加一个卫星,这里无需考虑顺序问题,卫星主要靠名字搜索
* @param weiXingDataList 旧的卫星List数据
* @param newWX 新的卫星数据
* @return 新的卫星List数据
*/
List<WeiXingData> addWX(List<WeiXingData> weiXingDataList, WeiXingData newWX);
/**
* @description 删除指定的卫星
* @param weiXingDataList 旧的卫星List数据
* @param appName 指定卫星的名字
* @return 新的卫星List
*/
List<WeiXingData> delWX(List<WeiXingData> weiXingDataList, String appName);
/**
* @description 修改给定卫星的给定值,只能修改高度
* @param weiXingDataList 旧的卫星List
* @param appName 要修改的卫星名字
* @param field 要修改的属性
* @param val 要改成的值,传入为String类型,可在代码中转化为Double类型的值
* @return 新的卫星List
*/
List<WeiXingData> changeWX(List<WeiXingData> weiXingDataList, String appName, String field, String val);
/**
* @description 初始化拓扑
* @param file 传入文件路径
* @return 返回为卫星List
*/
List<WeiXingData> iniTopo(File file, int zhouqi) throws IllegalAccessException;
/**
* @description 改变拓扑
* @param wxData 旧的网络
* @param time 抽样时间
* @return 改变后的网络
*/
List<WeiXingData> changeTopo(List<WeiXingData> wxData, int time);
/**
* @description 增减卫星时需要调用
* @param wxData
* @return
*/
List<WeiXingData> initChangeTopo(List<WeiXingData> wxData, int zhouqi);
}
package top.ninwoo.test.sateTopo.service.impl;
import top.ninwoo.test.sateTopo.entity.SimData;
import top.ninwoo.test.sateTopo.entity.WeiXingData;
import top.ninwoo.test.sateTopo.service.Toponet;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
public class ToponetImpl implements Toponet {
@Override
public String[] getAppNames(List<WeiXingData> weiXingDataList) {
//先判断有多少个docker容器,并生成相对应的ovs
int n = weiXingDataList.size();
//创建docker容器和一个ovs的数组
String[] appNames = new String[n+1];
for(int j=0;j<n;j++){
appNames[j] = weiXingDataList.get(j).getName();
}
appNames[n] = "br:"+ "ovs";
return appNames;
}
@Override
public int[][] getTopology(List<WeiXingData> weiXingDataList, SimData simData) {
int n = weiXingDataList.size();
int[][] topu = new int[n+1][n+1];
//先将docker容器和ovs相连如:app1连br:ovs,app2连br:ovs
for (int i = 0; i < n; i++) {
topu[n][i] = 1;
}
//判断docker之间是否相通
for(int a=0;a<n;a++){
for(int b=a+1;b<n;b++){
//通过距离来判断
double channelCapacity = this.channelCapacity(weiXingDataList.get(a),weiXingDataList.get(b),simData);
if(channelCapacity>=simData.getC0()){
topu[b][a] = 1;
}
}
}
return topu;
}
@Override
public double[][] getWeightedTopology(List<WeiXingData> weiXingDataList, SimData simData) {
int n = weiXingDataList.size();
double[][] topu = new double[n+1][n+1];
//先将docker容器和ovs相连如:app1连br:ovs,app2连br:ovs
for (int i = 0; i < n; i++) {
topu[n][i] = 1;
}
//判断docker之间是否相通
for(int a=0;a<n;a++){
for(int b=a+1;b<n;b++){
//通过距离来判断
double channelCapacity = this.channelCapacity(weiXingDataList.get(a),weiXingDataList.get(b),simData);
if(channelCapacity>=simData.getC0()){
topu[b][a] = channelCapacity/1024/1024;
}
}
}
return topu;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Double distance(WeiXingData a, WeiXingData b) {
Double r;
r = Math.sqrt(Math.pow(a.getXaxis()-b.getXaxis(),2)+Math.pow(a.getYaxis()-b.getYaxis(),2)+Math.pow(a.getZaxis()-b.getZaxis(),2));
return r;
}
@Override
public Double channelCapacity(WeiXingData a, WeiXingData b, SimData sd) {
double r = this.distance(a, b);
double channelCapacity;
channelCapacity = sd.getBandwidth()*Math.log(1+(sd.ptGtGr()/(Math.pow(4*Math.PI*r*sd.getJiange()/sd.getLamda(),2)*sd.n0B())))/Math.log(2);
return channelCapacity;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void history(String[] appNames, int[][] topo) {
File file1 = new File("C:\\WorkSpace\\test\\history.txt");
try {
FileWriter fw = new FileWriter(file1,true);
BufferedWriter bw = new BufferedWriter(fw);
//先写上日期标记
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS" );
Date d= new Date();
String str = sdf.format(d);
bw.write(str + "开始的拓扑结构"+ "\n");
//todo 需要设计排版
int num = appNames.length;
int[][] logic = new int[num][num];
for(int i = 0; i<num;i++){
for(int m =0;m<num;m++){
logic[i][m] = topo[i+num][m+num];
bw.write(logic[i][m] + " ");
bw.flush();
}
bw.write("\n" );
bw.flush();
}
bw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void delHistory() {
File file = new File("C:\\WorkSpace\\test\\history.txt");
if (file.exists()) {
file.delete();
}
}
}
package top.ninwoo.test.sateTopo.service.impl;
import top.ninwoo.test.sateTopo.entity.SimData;
import top.ninwoo.test.sateTopo.entity.WeiXingData;
import top.ninwoo.test.sateTopo.service.Weixing;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WeixingImpl implements Weixing {
SimData simData = new SimData();
@Override
public List<Map> parseTxt(File file) {
String str;
List<Map> maps = new ArrayList<Map>();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
while((str = br.readLine()) != null){
if(str.equals("-------------")){
//WeiXing initwx = new WeiXing();
Map<String,String> map = new HashMap();
str = br.readLine();
while(str.equals("-------------")==false){
String[] split = str.split("=");
//if(split(0)==initwx.)
map.put(split[0], split[1]);
str = br.readLine();
}
maps.add(map);
}
}
}catch (Exception e){
e.printStackTrace();
}
return maps;
}
@Override
public WeiXingData initWX(Class wx, Map map) throws IllegalAccessException {
WeiXingData initwx = new WeiXingData();
Field[] fields = wx.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if (field.getType() == Float.class) {
field.set(initwx, Float.parseFloat((String) map.get(field.getName())));
} else if (field.getType() == String.class) {
field.set(initwx, map.get(field.getName()));
}else if (field.getType() == Boolean.class) {
if(map.get(field.getName()).equals("true")){
field.set(initwx, true);
}else{field.set(initwx, false);}
}
}
return initwx;
}
@Override
public List<WeiXingData> initNet(List<Map> maps) throws IllegalAccessException {
List<WeiXingData> initnet = new ArrayList<>();
for(int i=0;i<maps.size();i++){
WeiXingData wx = new WeiXingData();
wx = this.initWX(WeiXingData.class,maps.get(i));
initnet.add(wx);
}
return initnet;
}
@Override
public List<WeiXingData> addWSpeed(List<WeiXingData> wx, int zhouqi) {
for(int i=0;i<wx.size();i++){
if(wx.get(i).getTag().equals(true)){
wx.get(i).setSpeed(2*Math.PI*(1/zhouqi));}
else{wx.get(i).setSpeed((-1)*2*Math.PI*(1/zhouqi));}
}
return wx;
}
@Override
public List<WeiXingData> addAxis(List<WeiXingData> wx) {
for (int i = 0; i < wx.size(); i++) {
Float High = wx.get(i).getHigh();
Double hudu = Math.toRadians(wx.get(i).getSpeed() * wx.get(i).getLastime());
Double Alpha = Math.toRadians(wx.get(i).getAlpha());
Double Beta = Math.toRadians(wx.get(i).getBeta());
Double Gamma = Math.toRadians(wx.get(i).getGamma());
wx.get(i).setXaxis(High * Math.cos(hudu + Gamma) * Math.sin(Beta) + High * Math.sin(hudu + Gamma) * Math.cos(Alpha) * Math.cos(Beta));
wx.get(i).setYaxis(High * Math.cos(hudu + Gamma) * Math.cos(Beta) - High * Math.sin(hudu + Gamma) * Math.cos(Alpha) * Math.sin(Beta));
wx.get(i).setZaxis(High * Math.sin(hudu + Gamma) * Math.sin(Alpha));
}
return wx;
}
@Override
public boolean addIndex(List<WeiXingData> wx) {
for(int i=0;i<wx.size();i++){
wx.get(i).setIndex(i+1);
}
return true;
}
@Override
public boolean checkIndex(List<WeiXingData> wx) {
boolean k=false;
int tag = 0;
for(int m=0;m<wx.size();m++){
if(wx.get(m).getIndex() == m+1){
tag++;
}else{
wx.get(m).setIndex(m+1);
m=m-1;
}
}
if(tag == wx.size()){
k = true;
}
return k;
}
@Override
public void checkWX(List<WeiXingData> wx) {
for(int i=0;i<wx.size();i++){
for(int j=i+1;j<wx.size();j++){
if(wx.get(i).getName().equals(wx.get(j).getName())){
String str = wx.get(i).getName() + i + j;
wx.get(j).setName(str);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Integer findindex(List<WeiXingData> weiXingDataList, String appName) {
Integer index = 0;
for(int i=0;i<weiXingDataList.size();i++){
if(weiXingDataList.get(i).getName().equals(appName)){
index = weiXingDataList.get(i).getIndex();
break;
}
}
return index;
}
@Override
public WeiXingData findWX(List<WeiXingData> weiXingDataList, String appName) {
WeiXingData wxData = null;
int k = findindex(weiXingDataList,appName);
if(k != 0){
wxData = weiXingDataList.get(k-1);
}
return wxData;
}
//增加和删除卫星需要反求(球坐标)
@Override
public List<WeiXingData> addWX(List<WeiXingData> weiXingDataList, WeiXingData newWX) {
//先判断是否已存在相同名字的卫星
WeiXingData wxdata = findWX(weiXingDataList,newWX.getName());
if(wxdata != null){
//加上时间这一唯一标识
newWX.setName(newWX.getName()+System.currentTimeMillis());
}
weiXingDataList.add(newWX);
//修改坐标系
for(int i=0;i<weiXingDataList.size()-1;i++){
float gamma = (float) (weiXingDataList.get(i).getGamma()+weiXingDataList.get(i).getLastime()*weiXingDataList.get(i).getSpeed());
weiXingDataList.get(i).setGamma(gamma);
weiXingDataList.get(i).setLastime(0);
}
this.addIndex(weiXingDataList);
this.checkIndex(weiXingDataList);
return weiXingDataList;
}
@Override
public List<WeiXingData> delWX(List<WeiXingData> weiXingDataList, String appName) {
//找到该卫星
WeiXingData wxdata = findWX(weiXingDataList,appName);
if(wxdata != null){
weiXingDataList.remove(wxdata.getIndex()-1);
}
//修改坐标系
for(int i=0;i<weiXingDataList.size();i++){
float gamma = (float) (weiXingDataList.get(i).getGamma()+weiXingDataList.get(i).getLastime()*weiXingDataList.get(i).getSpeed());
weiXingDataList.get(i).setGamma(gamma);
weiXingDataList.get(i).setLastime(0);
}
this.addIndex(weiXingDataList);
this.checkIndex(weiXingDataList);
return weiXingDataList;
}
//todo 只考虑增加高度一个选项
@Override
public List<WeiXingData> changeWX(List<WeiXingData> weiXingDataList, String appName, String field, String val) {
return null;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public List<WeiXingData> iniTopo(File file, int zhouqi) throws IllegalAccessException {
List<Map> maps = this.parseTxt(file);
List<WeiXingData> wxData = this.initNet(maps);
wxData = this.initChangeTopo(wxData,zhouqi);
return wxData;
}
@Override
public List<WeiXingData> changeTopo(List<WeiXingData> wxData, int time) {
for(int i=0;i<wxData.size();i++){
wxData.get(i).setLastime(time);
}
wxData = this.addAxis(wxData);
this.addIndex(wxData);
this.checkIndex(wxData);
return wxData;
}
@Override
public List<WeiXingData> initChangeTopo(List<WeiXingData> wxData, int zhouqi) {
wxData = this.addWSpeed(wxData,zhouqi);
wxData = this.addAxis(wxData);
this.checkWX(wxData);
this.addIndex(wxData);
this.checkIndex(wxData);
return wxData;
}
}
bishe.app.app-name=joliu
bishe.app.cloud-url=192.168.47.130:9091
bishe.app.cloud-url=192.168.31.198:9091
# bishe.app.cloud-url=192.168.31.198:9090
eta=0.7
targetIp=172.17.0.2
......
......@@ -3,27 +3,33 @@ package com.pitong.business;
import com.pitong.business.item.DataPackage;
import com.pitong.business.item.Picture;
import com.pitong.business.service.IPService;
import com.pitong.business.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.stereotype.Service;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.*;
import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
@Service
@SpringBootApplication
public class Application implements ApplicationRunner {
@Autowired
private ServerService serverService;
@Autowired
private IPService ipService;
@Value("${slot}")
private Long slot; //时隙值
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class)
......@@ -46,6 +52,33 @@ public class Application implements ApplicationRunner {
objectInputStream = new ObjectInputStream(new BufferedInputStream(inputStream));
Object object = objectInputStream.readObject();
DataPackage dataPackage = (DataPackage) object;
Stack[] route = dataPackage.getRoute();
int routeNumber = dataPackage.getRouteNumber();
int[] mapping = {0,1,2,3,4,5,5,6};
List<Integer> sequencet = dataPackage.getSequence();
int currentHop = dataPackage.getCurrentHop();
if (!route[routeNumber].empty()){
//发送到其他卫星计算,本卫星只转发
//get下一转发节点
Integer nextHop = (Integer) route[routeNumber].pop();
System.out.println("cover transfer next sate:"+nextHop);
//重新组合数据包
dataPackage.setRoute(route);
dataPackage.setCurrentHop(nextHop);
transferPackage(dataPackage, nextHop, startime);
continue;
}else if(sequencet.get(mapping[routeNumber])!=currentHop){
int nextHop = sequencet.get(mapping[routeNumber]);
System.out.println("routeNumber"+routeNumber);
System.out.println("currentHop:"+currentHop+" task exec sate"+nextHop);
dataPackage.setCurrentHop(nextHop);
transferPackage(dataPackage, nextHop, startime);
continue;
}
int number = dataPackage.getNumber();
List<Integer> sequence = dataPackage.getSequence();
Picture picture = dataPackage.getPicture();
......@@ -55,12 +88,15 @@ public class Application implements ApplicationRunner {
Long Currentime = dataPackage.getCurrentime();
Long fun1time = dataPackage.getFun1time();
List<Double> compCapacity = dataPackage.getCompCapacity();
LinkedList<Double> tranDelay =dataPackage.getTranDelay();
System.out.println("route array"+tranDelay);
System.out.println("=====================");
System.out.println("running");
String methodName = "func" + number;
Method method = serverService.getClass().getMethod(methodName, Class.forName("java.util.List"), Picture.class, Class.forName("java.lang.String"), Class.forName("java.lang.Double"),
Class.forName("java.lang.Long"),Class.forName("java.lang.Long"), Class.forName("java.lang.Long"), Class.forName("java.util.List"));
method.invoke(serverService, sequence, picture, loc, eta, Currentime, startime, fun1time, compCapacity);
Class.forName("java.lang.Long"),Class.forName("java.lang.Long"), Class.forName("java.lang.Long"), Class.forName("java.util.List"), route.getClass(), Class.forName("java.util.LinkedList"));
method.invoke(serverService, sequence, picture, loc, eta, Currentime, startime, fun1time, compCapacity, route, tranDelay);
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
......@@ -80,4 +116,39 @@ public class Application implements ApplicationRunner {
}
}
}
private void transferPackage(DataPackage dataPackage, int nextHop, long startime) {
//获取目标节点ip
String app_name = "sate" + nextHop;
String IP = ipService.getIpByAppName(app_name);
//发送至目标
send(dataPackage, IP, 2020, startime);
}
private void send(DataPackage dataPackage, String ip, int port, Long startime) {
Socket socket = null;
try {
socket = new Socket(ip, port);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
objectOutputStream.writeObject(dataPackage);
} catch (IOException e) {
Long waitime = slot-(System.currentTimeMillis()-startime)%slot;
try {
Thread.sleep(waitime+10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println(">>>>>>>>>>>>>>>>>>>");
System.out.println("blocked current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
System.out.println("try again ...");
send(dataPackage, ip, port, startime);
} finally {
try {
if (socket != null) {
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
......@@ -3,6 +3,7 @@ package com.pitong.business.service;
import com.pitong.business.item.DataPackage;
import com.pitong.business.item.Picture;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -11,6 +12,7 @@ import java.io.*;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
@Service
@parameters
......@@ -53,10 +55,12 @@ public class ServerService {
// }
public void func1(List<Integer> sequence, Picture picture, String loc, Double eta,
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity) {
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity, Stack[] route, LinkedList<Double> tranDelay) {
saveToFile(picture, in_file);
fun1time = System.currentTimeMillis();
long l1 = System.currentTimeMillis();
saveToFile(picture, in_file);
communicationToCloud("==========================");
System.out.println("=========1==========");
communicationToCloud("receive from sate"+sequence.get(0));
......@@ -67,62 +71,115 @@ public class ServerService {
double compCap = compCapacity.get(sequence.get(0)-1);
long length = picture.getData().length/1024;
System.out.println(length);
communicationToCloud("picture size"+length);
// communicationToCloud("picture size"+length);
System.out.println("=========3==========");
Long latency = Math.round(length/compCap);
// System.out.println(latency-(l11-fun1time));
try {
if(latency > (l11-fun1time)){
Thread.sleep(latency-Math.round(l11-fun1time));
if(latency > (l11- l1)){
Thread.sleep(latency-Math.round(l11- l1));
// System.out.println("true");
}
} catch (InterruptedException e) {
e.printStackTrace();
}
long l1 = System.currentTimeMillis();
communicationToCloud("task 1 spend time: "+(l1-fun1time)+"ms");
long l111 = System.currentTimeMillis();
communicationToCloud("task 1 spend time: "+(l111- l1)+"ms");
communicationToCloud("--------------------------");
System.out.println("=========4==========");
System.out.println("task 1 spend time: "+(l1-fun1time)+"ms");
System.out.println("task 1 spend time: "+(l111- l1)+"ms");
System.out.println("---------------------");
DataPackage dataPackage1 = combine(2, sequence, loc, out_file1, l1, fun1time, compCapacity);
DataPackage dataPackage2 = combine(3, sequence, loc, out_file2, l1, fun1time, compCapacity);
Long finalFun1time = fun1time;
new Thread(new Runnable() {
@Override
public void run() {
if (!route[1].empty()){
Integer nextHop = (Integer) route[1].pop();
DataPackage dataPackage1 = combine(2,1, sequence, loc, out_file1, l111, finalFun1time, compCapacity,route,nextHop, tranDelay);
String app_name2 = "sate" + nextHop;
System.out.println("transfer next relay sate:"+nextHop);
String IP2 = ipService.getIpByAppName(app_name2);
send(dataPackage1, IP2, 2020, startime);
communicationToCloud("transfer next relay sate:"+nextHop);
communicationToCloud("==========================");
}else{
DataPackage dataPackage1 = combine(2,1, sequence, loc, out_file1, l111, finalFun1time, compCapacity,route,sequence.get(1), tranDelay);
String app_name2 = "sate" + sequence.get(1);
String IP2 = ipService.getIpByAppName(app_name2);
String app_name3 = "sate" + sequence.get(2);
String IP3 = ipService.getIpByAppName(app_name3);
startime += 20*1000;
communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
//communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
send(dataPackage1, IP2, 2020, startime);
communicationToCloud("transmission success!");
System.out.println("transmission success!");
communicationToCloud("transfer next exec sate:"+sequence.get(1));
communicationToCloud("==========================");
System.out.println("=====================");
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
}
}
}).start();
Long finalFun1time1 = fun1time;
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!route[2].empty()){
Integer nextHop = (Integer) route[2].pop();
DataPackage dataPackage2 = combine(3, 2,sequence, loc, out_file2, l111, finalFun1time1, compCapacity,route,nextHop, tranDelay);
String app_name3 = "sate" + nextHop;
System.out.println("transfer next sate:"+nextHop);
String IP3 = ipService.getIpByAppName(app_name3);
send(dataPackage2, IP3, 2020, startime);
communicationToCloud("transfer next relay sate:"+nextHop);
communicationToCloud("==========================");
}else{
DataPackage dataPackage2 = combine(3, 2,sequence, loc, out_file2, l111, finalFun1time1, compCapacity,route,sequence.get(2), tranDelay);
String app_name3 = "sate" + sequence.get(2);
String IP3 = ipService.getIpByAppName(app_name3);
//startime += 20*1000;
//communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
send(dataPackage2, IP3, 2020, startime);
communicationToCloud("transmission success!");
//communicationToCloud("transmission success!");
System.out.println("transmission success!");
communicationToCloud("transfer next exec sate:"+sequence.get(2));
communicationToCloud("==========================");
System.out.println("=====================");
}
}
}).start();
sendToCloud(list);
}
public void func2(List<Integer> sequence, Picture picture, String loc, Double eta, Long Currentime,
Long startime, Long fun1time, List<Double> compCapacity) {
Long startime, Long fun1time, List<Double> compCapacity, Stack[] route, LinkedList<Double> tranDelay) {
long l2 = System.currentTimeMillis();
long l2t = System.currentTimeMillis();
System.out.println(tranDelay);
// System.out.println(tranDelay.get(0));
System.out.println(Currentime);
transLatency(l2t,Currentime,tranDelay.get(0));
communicationToCloud("==========================");
communicationToCloud("receive from sate"+sequence.get(1));
saveToFile(picture, in_file);
double compCap = compCapacity.get(sequence.get(1)-1);
long length = picture.getData().length/1024;
long l2 = System.currentTimeMillis();
greyProcess();
......@@ -143,31 +200,63 @@ public class ServerService {
communicationToCloud("task 2 Spend time: "+(l21-l2)+"ms");
System.out.println("---------------------");
communicationToCloud("--------------------------");
DataPackage dataPackage = combine(4, sequence, loc, out_file, l21, fun1time, compCapacity);
if (!route[3].empty()){
Integer nextHop = (Integer) route[3].pop();
DataPackage dataPackage = combine(4,3, sequence, loc, out_file, l21, fun1time, compCapacity, route,nextHop, tranDelay);
String app_name4 = "sate" + nextHop;
System.out.println("transfer next sate:"+nextHop);
String IP4 = ipService.getIpByAppName(app_name4);
send(dataPackage, IP4, 2020, startime);
communicationToCloud("transfer next relay sate:"+nextHop);
communicationToCloud("==========================");
}else{
DataPackage dataPackage = combine(4,3, sequence, loc, out_file, l21, fun1time, compCapacity, route,sequence.get(3), tranDelay);
String app_name4 = "sate" + sequence.get(3);
String IP4 = ipService.getIpByAppName(app_name4);
communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
//communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
send(dataPackage, IP4, 2020, startime);
System.out.println("transmission success!");
communicationToCloud("transmission success!");
communicationToCloud("transfer next exec sate:"+sequence.get(3));
communicationToCloud("==========================");
/*communicationToCloud("transmission success!");
communicationToCloud("==========================");*/
}
sendToCloud(list);
System.out.println("=====================");
}
private void transLatency(long l2, Long currentime, Double aDouble) {
if ((l2 - currentime) < aDouble){
try {
if (aDouble < 20000){
Thread.sleep(Math.round(aDouble-(l2 - currentime)));
}/*else {
if ((l2 - currentime) < 20000)
Thread.sleep(Math.round(20000-(l2 - currentime)));
}*/
} catch (InterruptedException e) {
e.printStackTrace();
}
}
communicationToCloud("route delay "+(System.currentTimeMillis()-currentime)+"ms");
}
public void func3(List<Integer> sequence, Picture picture, String loc, Double eta,
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity) {
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity, Stack[] route, LinkedList<Double> tranDelay) {
long l2 = System.currentTimeMillis();
long l2t = System.currentTimeMillis();
transLatency(l2t,Currentime,tranDelay.get(1));
saveToFile(picture, in_file);
communicationToCloud("==========================");
communicationToCloud("receive from sate"+sequence.get(2));
double compCap = compCapacity.get(sequence.get(2)-1);
long length = picture.getData().length/1024;;
long length = picture.getData().length/1024;
long l2 = System.currentTimeMillis();
greyProcess();
long l20 = System.currentTimeMillis();
Long latency = Math.round(length/compCap);
......@@ -186,41 +275,52 @@ public class ServerService {
communicationToCloud("--------------------------");
System.out.println("task 3 Spend time: "+(l22-l2)+"ms");
System.out.println("---------------------");
DataPackage dataPackage = combine(5, sequence, loc, out_file, l22, fun1time, compCapacity);
if (!route[4].empty()){
Integer nextHop = (Integer) route[4].pop();
DataPackage dataPackage = combine(5,4, sequence, loc, out_file, l22, fun1time, compCapacity, route,nextHop, tranDelay);
String app_name5 = "sate" + nextHop;
System.out.println("transfer next sate:"+nextHop);
String IP5 = ipService.getIpByAppName(app_name5);
send(dataPackage, IP5, 2020, startime);
communicationToCloud("transfer next relay sate:"+nextHop);
communicationToCloud("==========================");
}else{
DataPackage dataPackage = combine(5,4, sequence, loc, out_file, l22, fun1time, compCapacity, route,sequence.get(4), tranDelay);
String app_name5 = "sate" + sequence.get(4);
String IP5 = ipService.getIpByAppName(app_name5);
communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
//communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
send(dataPackage, IP5, 2020, startime);
communicationToCloud("transmission success!");
communicationToCloud("transfer next exec sate:"+sequence.get(4));
communicationToCloud("==========================");
}
sendToCloud(list);
System.out.println("transmission success!");
System.out.println("=====================");
}
public void func4(List<Integer> sequence, Picture picture, String loc, Double eta,
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity) {
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity, Stack[] route, LinkedList<Double> tranDelay) {
long l2 = System.currentTimeMillis();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
long l2t = System.currentTimeMillis();
transLatency(l2t,Currentime,tranDelay.get(2));
saveToFile(picture, in_file);
communicationToCloud("==========================");
communicationToCloud("receive from sate"+sequence.get(3));
double compCap = compCapacity.get(sequence.get(3)-1);
long length = picture.getData().length/1024;
long l2 = System.currentTimeMillis();
binaryProcess();
long l20 = System.currentTimeMillis();
Long latency = Math.round(length/compCap);
// System.out.println(latency-(l20-l2));
try {
if(latency > (l20-Currentime)){
if(latency > (l20-l2)){
Thread.sleep(latency-(l20-l2));
// System.out.println("true");
}
......@@ -234,30 +334,45 @@ public class ServerService {
System.out.println("---------------------");
communicationToCloud("task 4 Spend time: "+(l22-l2)+"ms");
communicationToCloud("--------------------------");
DataPackage dataPackage = combine(6, sequence, "top", out_file, l22, fun1time, compCapacity);
if (!route[5].empty()){
Integer nextHop = (Integer) route[5].pop();
DataPackage dataPackage = combine(6,5, sequence, "top", out_file, l22, fun1time, compCapacity, route,nextHop, tranDelay);
String app_name6 = "sate" + nextHop;
System.out.println("transfer next sate:"+nextHop);
String IP6 = ipService.getIpByAppName(app_name6);
send(dataPackage, IP6, 2020, startime);
communicationToCloud("transfer next relay sate:"+nextHop);
communicationToCloud("==========================");
}else{
DataPackage dataPackage = combine(6,5, sequence, "top", out_file, l22, fun1time, compCapacity, route,sequence.get(5), tranDelay);
String app_name6 = "sate" + sequence.get(5);
String IP6 = ipService.getIpByAppName(app_name6);
communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
send(dataPackage, IP6, 2020, startime);
communicationToCloud("transmission success!");
communicationToCloud("transfer next exec sate:"+sequence.get(5));
communicationToCloud("==========================");
}
sendToCloud(list);
System.out.println("transmission success!");
System.out.println("=====================");
}
public void func5(List<Integer> sequence, Picture picture, String loc, Double eta,
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity) {
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity, Stack[] route, LinkedList<Double> tranDelay) {
long l2 = System.currentTimeMillis();
long l2t = System.currentTimeMillis();
transLatency(l2t,Currentime,tranDelay.get(3));
saveToFile(picture, in_file);
communicationToCloud("==========================");
communicationToCloud("receive from sate"+sequence.get(4));
double compCap = compCapacity.get(sequence.get(4)-1);
long length = picture.getData().length/1024;
long l2 = System.currentTimeMillis();
binaryProcess();
long l20 = System.currentTimeMillis();
......@@ -278,14 +393,27 @@ public class ServerService {
communicationToCloud("--------------------------");
System.out.println("task 5 Spend time: "+(l22-l2)+"ms");
System.out.println("---------------------");
DataPackage dataPackage = combine(6, sequence, "bottom", out_file, l22, fun1time, compCapacity);
if (!route[6].empty()){
Integer nextHop = (Integer) route[6].pop();
DataPackage dataPackage = combine(6,6, sequence, "bottom", out_file, l22, fun1time, compCapacity, route,nextHop, tranDelay);
String app_name6 = "sate" + nextHop;
System.out.println("transfer next sate:"+nextHop);
String IP6 = ipService.getIpByAppName(app_name6);
send(dataPackage, IP6, 2020, startime);
communicationToCloud("transfer next relay sate:"+nextHop);
communicationToCloud("==========================");
}else{
DataPackage dataPackage = combine(6,6, sequence, "bottom", out_file, l22, fun1time, compCapacity, route,sequence.get(5), tranDelay);
String app_name6 = "sate" + sequence.get(5);
String IP6 = ipService.getIpByAppName(app_name6);
communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
//communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
send(dataPackage, IP6, 2020, startime);
communicationToCloud("transmission success!");
communicationToCloud("transfer next exec sate:"+sequence.get(5));
communicationToCloud("==========================");
}
sendToCloud(list);
System.out.println("transmission success!");
System.out.println("=====================");
......@@ -293,10 +421,10 @@ public class ServerService {
static Long Currentime1 = 0L;
public void func6(List<Integer> sequence, Picture picture, String loc, Double eta,
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity) {
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity, Stack[] route, LinkedList<Double> tranDelay) {
long l2 = System.currentTimeMillis();
long l2t = System.currentTimeMillis();
// System.out.println("picture size: "+ length +"K");
if (loc.equals("top")) {
......@@ -307,9 +435,14 @@ public class ServerService {
File file1 = new File(in_file1);
File file2 = new File(in_file2);
long l2 = System.currentTimeMillis();
if (file1.exists() && file2.exists()) {
transLatency(l2t,Currentime,tranDelay.get(4)/2);
communicationToCloud("==========================");
communicationToCloud("receive from sate"+sequence.get(5));
long l2c = System.currentTimeMillis();
mergePorcess();
......@@ -319,8 +452,8 @@ public class ServerService {
long l20 = System.currentTimeMillis();
// System.out.println(latency-(l20-Currentime1));
try {
if(latency > l20-Currentime1){
Thread.sleep(latency-(l20-Currentime1));
if(latency > l20-l2c){
Thread.sleep(latency-(l20-l2c));
// System.out.println("ture");
}
} catch (InterruptedException e) {
......@@ -328,20 +461,31 @@ public class ServerService {
}
long l22 = System.currentTimeMillis();
// System.out.println("exec end timestamp: " + l22);
communicationToCloud("task 6 Spend time: " + (l22 - Currentime1) + "ms");
communicationToCloud("task 6 Spend time: " + (l22 - l2c) + "ms");
communicationToCloud("--------------------------");
System.out.println("task 6 Spend time: " + (l22 - Currentime1) + "ms");
System.out.println("task 6 Spend time: " + (l22 - l2c) + "ms");
System.out.println("---------------------");
DataPackage dataPackage = combine(7, sequence, null, out_file, l22, fun1time, compCapacity);
if (!route[7].empty()){
Integer nextHop = (Integer) route[7].pop();
DataPackage dataPackage = combine(7,7, sequence, null, out_file, l22, fun1time, compCapacity, route,nextHop, tranDelay);
String app_name7 = "sate" + nextHop;
String IP7 = ipService.getIpByAppName(app_name7);
send(dataPackage, IP7, 2020, startime);
communicationToCloud("transfer next relay sate:"+nextHop);
communicationToCloud("==========================");
}else{
DataPackage dataPackage = combine(7,7, sequence, null, out_file, l22, fun1time, compCapacity, route,sequence.get(6), tranDelay);
String app_name7 = "sate" + sequence.get(6);
String IP7 = ipService.getIpByAppName(app_name7);
startime += 20*1000;
System.out.println("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
//communicationToCloud("current slot: " + ((System.currentTimeMillis()-startime)/slot + 1));
send(dataPackage, IP7, 2020, startime);
communicationToCloud("transmission success!");
communicationToCloud("transfer next exec sate:"+sequence.get(6));
communicationToCloud("==========================");
}
sendToCloud(list);
System.out.println("transmission success!");
System.out.println("=====================");
......@@ -355,20 +499,18 @@ public class ServerService {
}
public void func7(List<Integer> sequence, Picture picture, String loc, Double eta,
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity) {
Long Currentime, Long startime, Long fun1time, List<Double> compCapacity, Stack[] route, LinkedList<Double> tranDelay) {
long l2 = System.currentTimeMillis();
/* try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
long l2t = System.currentTimeMillis();
transLatency(l2t,Currentime,tranDelay.get(5));
saveToFile(picture, in_file);
communicationToCloud("==========================");
communicationToCloud("receive from sate"+sequence.get(6));
double compCap = compCapacity.get(sequence.get(6)-1);
long length = picture.getData().length/1024;
long l2 = System.currentTimeMillis();
tailorProcess(coe);
......@@ -465,8 +607,8 @@ public class ServerService {
}
private DataPackage combine(int number, List<Integer> sequence, String loc, String file_path,
Long Currentime, Long fun1time, List<Double> compCapacity) {
private DataPackage combine(int number, int routeNumber, List<Integer> sequence, String loc, String file_path,
Long Currentime, Long fun1time, List<Double> compCapacity,Stack[] route, int nextHop, LinkedList<Double> tranDelay) {
DataPackage dataPackage = new DataPackage();
dataPackage.setNumber(number);
dataPackage.setPicture(loadPicture(file_path));
......@@ -475,6 +617,10 @@ public class ServerService {
dataPackage.setCurrentime(Currentime);
dataPackage.setFun1time(fun1time);
dataPackage.setCompCapacity(compCapacity);
dataPackage.setRoute(route);
dataPackage.setCurrentHop(nextHop);
dataPackage.setRouteNumber(routeNumber);
dataPackage.setTranDelay(tranDelay);
return dataPackage;
}
......
......@@ -13,7 +13,8 @@ public @interface parameters {
long slot() default 1000L*20;
String cldUrl() default "192.168.47.130";
String cldUrl() default "192.168.31.198";
// 192.168.47.130
int cldPort() default 8900;
}
......@@ -2,10 +2,10 @@
bishe:
app:
app-name: joliu
cloud-url: 192.168.47.130:9091
cloud-url: 192.168.31.198:9091
# cloud-url: 192.168.31.198:9090
slot: 20000 # 1000L*20
coe: 0.7
cldUrl: 192.168.47.130
cldUrl: 192.168.31.198
cldPort: 8900
......@@ -7,5 +7,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class WxMain {
public static void main(String[] args) {
SpringApplication.run(WxMain.class, args);
//init
}
}
......@@ -26,6 +26,13 @@ public interface Toponet {
*/
int[][] getTopology(List<WeiXingData> weiXingDataList, SimData simData);
/**
* @param weiXingDataList WeiXingData对象
* @return 二维数组,也就是拓扑图
* @description 得到网络拓扑形式类似为 app1 app2 app3 ovs1 ovs2 ovs3
*/
double[][] getWeightedTopology(List<WeiXingData> weiXingDataList, SimData simData);
/**
* @param a 具体的卫星a
* @param b 具体的卫星b
......
......@@ -48,6 +48,27 @@ public class ToponetImpl implements Toponet {
}
return topu;
}
@Override
public double[][] getWeightedTopology(List<WeiXingData> weiXingDataList, SimData simData) {
int n = weiXingDataList.size();
double[][] topu = new double[n+1][n+1];
//先将docker容器和ovs相连如:app1连br:ovs,app2连br:ovs
for (int i = 0; i < n; i++) {
topu[n][i] = 1;
}
//判断docker之间是否相通
for(int a=0;a<n;a++){
for(int b=a+1;b<n;b++){
//通过距离来判断
double channelCapacity = this.channelCapacity(weiXingDataList.get(a),weiXingDataList.get(b),simData);
if(channelCapacity>=simData.getC0()){
topu[b][a] = channelCapacity/1024/1024;
}
}
}
return topu;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public Double distance(WeiXingData a, WeiXingData b) {
......
bishe.app.app-name=joliu
bishe.app.cloud-url=127.0.0.1:9091
\ No newline at end of file
bishe.app.cloud-url=192.168.31.198:9091
\ No newline at end of file
......@@ -7,7 +7,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "bishe.app")
public class ClientProperties {
private String zookeeperUrl = "zookeeper://127.0.0.1:2181";
private String cloudUrl = "127.0.0.1:9300";
private String cloudUrl = "127.0.0.1:9300";//"192.168.47.130:9091";
private String appName = "default";
......
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