Commit 5e506afb authored by ymwang's avatar ymwang

单时隙业务

parent ecbbca86
...@@ -160,7 +160,6 @@ public class FileService { ...@@ -160,7 +160,6 @@ public class FileService {
return "failed!"; return "failed!";
} }
saveToFile(fileSlice,directoryOutput);
return response.getBody(); return response.getBody();
} }
...@@ -230,31 +229,4 @@ public class FileService { ...@@ -230,31 +229,4 @@ public class FileService {
fos.close(); fos.close();
} }
}
//在client将数据碎片传送至各个server上时,将数据包中的字节流存储在节点上
private void saveToFile(FileSlice fileSlice, String file_path) {
byte[] slice_data = fileSlice.getFileBytes();
File targetFile = new File(file_path);
if (targetFile.exists()) {
targetFile.delete();
}
//为什么创建父类
createParents(targetFile);
try {
targetFile.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(targetFile);
fileOutputStream.write(slice_data);
} catch (IOException e) {
e.printStackTrace();
}
}
private void createParents(File f) {
String parentName = f.getParent();
File parent = new File(parentName);
if (!parent.exists()) {
createParents(parent);
parent.mkdir();
}
}
}
\ No newline at end of file
package top.ninwoo.weixingsim.dynamicNet;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import static top.ninwoo.weixingsim.dynamicNet.CycleTopoUnit.cycleTp;
public class SingleSlotTopology {
/*
* 网络参数
*/
//设备数
static int num = 30;
//时隙大小
static double slot = 20*1000;
//时隙数目
static int slotnum;
//网络节点数
static int dev;
public static void main(String[] args) {
int[][] matrixGraph = SingleMatrixGraph();
for (int i = 0; i < matrixGraph.length; i++) {
for (int j = 0; j < matrixGraph[0].length; j++) {
System.out.print(matrixGraph[i][j]+" ");
}
System.out.println();
}
}
//业务发起时刻
public static long startT;
private static int[][] SingleMatrixGraph() {
//获取当前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,int[][]> cycleTp = cycleTp();
//获得第1个时隙的连接矩阵 0或1
int[][] currentTp = cycleTp.get((slotKey)%30+1);
int[][] slot1 = new int[num][num]; //10*10的矩阵图
for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1[0].length;j++){
slot1[i][j] = currentTp[i][j];
}
}
return slot1;
}
}
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