Commit fbbafe90 authored by Hu Jintao's avatar Hu Jintao

测试转发功能融合

parent 7cd86d1d
......@@ -12,6 +12,11 @@
<artifactId>business-api</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -4,118 +4,62 @@ import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
public class DataPackage implements Serializable {
private int number;
private List<Integer> sequence;
private Picture picture;
private String loc;
private double eta;
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;
}
import lombok.Data;
public int getCurrentHop() {
return currentHop;
}
@Data
public class DataPackage implements Serializable {
public void setCurrentHop(int currentHop) {
this.currentHop = currentHop;
}
public void setRouteNumber(int routeNumber) {
this.routeNumber = routeNumber;
}
//加入任务表:ConcurrentHashMap<卫星名字,功能函数名>
private ConcurrentHashMap<String,String> taskTable = new ConcurrentHashMap<>();
//加入路径表:String[]
private String[] pathTable = new String[]{};
//全局路由表:String[][]
private String[][] route = new String[][]{};
//本机卫星名
private String currentSataHop;
//下一跳卫星名
private String nextSataHop;
//该条路径的目的卫星名
private String destinSataHop;
//图像
private Picture picture;
public void setRoute(Stack[] route) {
this.route = route;
}
public int getRouteNumber() {
return routeNumber;
}
public Stack[] getRoute() {
return route;
}
public List<Double> getCompCapacity() {
return compCapacity;
}
public void setCompCapacity(List<Double> compCapacity) {
this.compCapacity = compCapacity;
}
public void setFun1time(Long fun1time) {
this.fun1time = fun1time;
}
public Long getFun1time() {
return fun1time;
}
public void setCurrentime(Long currentime) {
this.currentime = currentime;
}
public Long getCurrentime() {
return currentime;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public List<Integer> getSequence() {
return sequence;
}
public void setSequence(List<Integer> sequence) {
this.sequence = sequence;
}
public Picture getPicture() {
return picture;
}
public void setPicture(Picture picture) {
this.picture = picture;
}
public String getLoc() {
return loc;
}
public void setLoc(String loc) {
this.loc = loc;
}
public double getEta() {
return eta;
}
public void setEta(double eta) {
this.eta = eta;
}
/* private int number;
private List<Integer> sequence;
private Picture picture;
private String loc;
private double eta;
private Long currentime;
private Long fun1time;
private List<Double> compCapacity;
private LinkedList<Double> tranDelay;
//当前卫星节点
private int currentHop;
//路由新添解析步骤
private int routeNumber;
public Stack[] route;*/
}
......@@ -3,6 +3,7 @@ package top.ninwoo.test;
import com.pitong.business.item.DataPackage;
import com.pitong.business.item.Picture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
......@@ -12,18 +13,19 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import top.ninwoo.test.doMap.DoMap;
import top.ninwoo.test.doMap.path;
import top.ninwoo.test.transfer.TransferService;
import java.io.*;
import java.net.Socket;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@SpringBootApplication
@path
public class BisheTestMain implements ApplicationRunner {
@Value("${eta}")
private double ETA;
@Autowired
private TransferService transferService;
@Value("${targetIp}")
private String targetIp;
......@@ -47,13 +49,15 @@ public class BisheTestMain implements ApplicationRunner {
//子任务依赖关系 边
int[][] link = {{0, 0, 1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 5, 6}};
//task编号
int[] func = {1, 3, 3, 3, 2, 2, 4};
//功能分支表
int[][] branch = {{1, 1},{1, 2},{1, 1},{2, 1},{1, 1}};
int[] func = {2, 3, 1, 1, 3, 4, 5};
//task列表
String[] tasks = {" ","binaryProcess", "cutProcess", "greyProcess", "mergePorcess", "tailorProcess"};
// //功能分支表
// int[][] branch = {{1, 1},{1, 2},{1, 1},{2, 1},{1, 1}};
DoMap doMap = new DoMap();
doMap.doMapApp(link,func);
//将节点映射结果保存为List
//映射结果
int[] result = doMap.result;
boolean flag = repetition(result);
while (result[0] == 0 || flag){
......@@ -62,59 +66,53 @@ public class BisheTestMain implements ApplicationRunner {
result = doMap.result;
flag = repetition(result);
}
List<Integer> sequence = new ArrayList<>();
for (int a:result
) {
sequence.add(a);
}
//边映射结果T2
int[][] edgeMaps = new int[2][link[0].length];
edgeMaps[0][0] = 2;
for (int tm = 0;tm<link[0].length;tm++){
//第一列为边起点,第二列为边终点
edgeMaps[0][tm] = result[link[0][tm]];
edgeMaps[1][tm] = result[link[1][tm]];
}
//节点映射结果T1
HashMap<Integer,Integer> nodeMaps = new HashMap();
nodeMaps.put(1,func[0]);
DataPackage dataPackage = new DataPackage();
//路径表
String[] path = new String[link[0].length];
for (int tm = 0;tm<link[0].length;tm++){
if (!nodeMaps.containsKey(result[link[1][tm]])){
//key值为节点映射卫星编号,value值为图像处理功能编号
nodeMaps.put(result[link[1][tm]],func[link[1][tm]]);
//左为边起点,右为边终点
path[tm] = "sate"+result[link[0][tm]]+"->"+"sate"+result[link[1][tm]];
}
dataPackage.setPathTable(path);
//任务表
ConcurrentHashMap<String,String> taskTable = new ConcurrentHashMap();
for (int tm = 0;tm<result.length;tm++){
taskTable.put("sate"+result[tm],tasks[func[tm]]);
}
dataPackage.setTaskTable(taskTable);
//T3路由表
int [][] lastHop = doMap.lastHop;
String[][] route = new String[lastHop.length][lastHop[0].length];
for(int i =0;i<lastHop.length;i++){
for (int j=0;j<lastHop[0].length;j++){
route[i][j] = "sate"+lastHop[i][j];
}
}
dataPackage.setRoute(route);
System.out.println("exec start timestamp: " + System.currentTimeMillis());
System.out.println("========================================");
System.out.println();
String file_path = "passport.jpg";
Picture picture = loadPicture(file_path);
dataPackage.setPicture(picture);
dataPackage.setCurrentSataHop("sate1");
dataPackage.setNextSataHop("sate1");
dataPackage.setDestinSataHop("sate1");
Date date = new Date();
long time = date.getTime();
transferService.transferPackage(dataPackage,dataPackage.getCurrentSataHop(),time);
// String loc = null;
String file_path = "passport.jpg";
/* int number = 1;
Long currentime = System.currentTimeMillis();
Long fun1time = Long.valueOf(0);
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.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(file_path, lastHop, edgeMaps, nodeMaps);
// send(dataPackage, targetIp, 2020);
}
private boolean repetition(int[] result) {
HashSet<Integer> set = new HashSet<>();
for (int a : result){
......@@ -132,19 +130,6 @@ public class BisheTestMain implements ApplicationRunner {
}
}
private static DataPackage combine(int number, List<Integer> sequence, String loc, String file_path,
Long Currentime, Long fun1time, List<Double> compCapacity,
LinkedList<Double> tranDelay) {
DataPackage dataPackage = new DataPackage();
dataPackage.setNumber(number);
dataPackage.setPicture(loadPicture(file_path));
dataPackage.setSequence(sequence);
dataPackage.setCurrentime(Currentime);
dataPackage.setFun1time(fun1time);
dataPackage.setCompCapacity(compCapacity);
dataPackage.setTranDelay(tranDelay);
return dataPackage;
}
private static Picture loadPicture(String pic_url) {
try {
......@@ -162,7 +147,7 @@ public class BisheTestMain implements ApplicationRunner {
return null;
}
private static void send(DataPackage dataPackage, String ip, int port) {
/* private static void send(DataPackage dataPackage, String ip, int port) {
Socket socket = null;
try {
socket = new Socket(ip, port);
......@@ -179,6 +164,33 @@ public class BisheTestMain implements ApplicationRunner {
e.printStackTrace();
}
}
}
}*/
}
/* List<Integer> sequence = new ArrayList<>();
for (int a:result
) {
sequence.add(a);
}*/
//边映射结果T2
/* int[][] edgeMaps = new int[2][link[0].length];
edgeMaps[0][0] = 2;
for (int tm = 0;tm<link[0].length;tm++){
//第一列为边起点,第二列为边终点
edgeMaps[0][tm] = result[link[0][tm]];
edgeMaps[1][tm] = result[link[1][tm]];
}*/
/*
HashMap<Integer,Integer> nodeMaps = new HashMap();
nodeMaps.put(1,func[0]);
for (int tm = 0;tm<link[0].length;tm++){
if (!nodeMaps.containsKey(result[link[1][tm]])){
//key值为节点映射卫星编号,value值为图像处理功能编号
nodeMaps.put(result[link[1][tm]],func[link[1][tm]]);
}
}*/
......@@ -74,9 +74,9 @@ public class CycleTopo {
Iterator<Map.Entry<Integer, double[][]>> iterator = TopoStore.entrySet().iterator();
while (iterator.hasNext()){
double[][] value = iterator.next().getValue();
System.out.println(Arrays.deepToString(value));
/* System.out.println(Arrays.deepToString(value));
System.out.println("=========================================");
System.out.println(count2);
System.out.println(count2);*/
while (iterator.hasNext()){
double[][] valueNext = iterator.next().getValue();
for (int i = 0;i<value.length;i++){
......@@ -85,9 +85,9 @@ public class CycleTopo {
}
if (count != 30){
System.out.println(Arrays.deepToString(valueNext));
System.out.println("=========================================");
System.out.println(count2);
// System.out.println(Arrays.deepToString(valueNext));
// System.out.println("=========================================");
// System.out.println(count2);
count2++;
}
count=0;
......
......@@ -123,8 +123,8 @@ public class DoMap {
lt[i][j];
}
}*/
System.out.println("最短路由");
System.out.println(Arrays.deepToString(lt));
/* System.out.println("最短路由");
System.out.println(Arrays.deepToString(lt));*/
//计算时延
/*for (int i = 0;i<nt.length;i++) {
nt[i] = (D[i] * 1000) / nt[i];
......@@ -172,18 +172,19 @@ public class DoMap {
end = lastHop[start][end];
}
}
System.out.println("--------------------------");
System.out.println("shortest route : ");
/* 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]]);
if (route[i+1].empty()){}
// System.out.print(result[link[0][i]]+"-->"+result[link[1][i]]);
else {
System.out.print(result[link[0][i]] + "-->");
// 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 + "-->");
// System.out.print(pop + "-->");
//顺便将数值转换
stack.push((pop-1)%num+1);
}
......@@ -191,12 +192,12 @@ public class DoMap {
while (items.hasMoreElements()) //显示枚举(stack ) 中的所有元素
System.out.print(items.nextElement() + "-->");*/
System.out.print(result[link[1][i]]);
// System.out.print(result[link[1][i]]);
while(!stack.isEmpty()){
route[i+1].push(stack.pop());
}
}
System.out.println(); //换行
// System.out.println(); //换行
}
//规范result 和 route 数据
for (int i = 0;i<result.length;i++){
......
package top.ninwoo.test.transfer;
import java.util.concurrent.ConcurrentHashMap;
/**
* 发现路由
*/
public interface FindService{
/**
* 根据路径表,找到本机需要处理路径条数
* c->a ==> sata1->sata3
*/
String[] findDestinSataHops(String[] pathTable, String currenthop);
/**
* 根据本机卫星名,全局路由表,路由表得到本机路由表
*/
String[] findRoute(String currentSataHo, String[][] routeTable);
/**
* 根据目的卫星名,本机路由表找到下一跳卫星名
*/
String findNextHop(String destinSataHop, String[] route);
/**
* 找到本机的任务
*/
String findTask(String currenSataHop, ConcurrentHashMap<String, String> taskMap);
}
\ No newline at end of file
package top.ninwoo.test.transfer;
/**
* 功能函数:灰度,二值。。。
*/
public interface FunctionService {
//Sample:建议取0~9整数
void add1(int a);
void add(int a);
void addself(int a);
void square(int a);
int getRes();
}
\ No newline at end of file
package top.ninwoo.test.transfer;
import com.pitong.business.item.DataPackage;
/**
* 转发数据包
*/
public interface TransferService {
void transferPackage(DataPackage dataPackage, String nextHop, long startime);
}
package top.ninwoo.test.transfer.impl;
import org.springframework.stereotype.Service;
import top.ninwoo.test.transfer.FindService;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class FindServiceImpl implements FindService {
@Override
public String[] findDestinSataHops(String[] pathTable,String currenthop) {
String[] destinSataHops = new String[]{};
int j = 0;
if(pathTable.length == 0){
System.out.println("路径表为空");
destinSataHops[0] = "nopara";
return destinSataHops;
}
for (int i = 0; i < pathTable.length; i++) {
//判断本机是否为路径起点
if(currenthop.equals(pathTable[i].split("->")[0])){
destinSataHops[j++] = pathTable[i].split("->")[1];
}
}
if(destinSataHops.length == 0){
destinSataHops[0] = "nolast";
}
return destinSataHops;
}
@Override
public String[] findRoute(String currentSataHop,String[][] routeTable) {
//判断路由表是否存在
if(routeTable.length == 0){
System.out.println("路由表为空");
return null;
}
//找到本机路由表
String[] route = this.findCurrentRoute(currentSataHop,routeTable);
return route;
}
@Override
public String findNextHop(String destinSataHop, String[] route) {
int index = Integer.parseInt(destinSataHop.split("sate")[1]);
String nextHop = route[index-1];
return nextHop;
}
@Override
public String findTask(String currenSataHop, ConcurrentHashMap<String, String> taskMap) {
if(taskMap.isEmpty()){
System.out.println("无任务表");
return null;
}
return taskMap.get(currenSataHop);
}
//找到本卫星的路由
private String[] findCurrentRoute(String sataname, String[][] routeTable){
int index = Integer.parseInt(sataname.split("sate")[1]);
return routeTable[index-1];
}
}
package top.ninwoo.test.transfer.impl;
import org.springframework.stereotype.Service;
import top.ninwoo.test.transfer.FunctionService;
import java.util.ArrayList;
@Service
public class FunctionServiceImpl implements FunctionService {
private ArrayList<Integer> addArray = new ArrayList<>();
private int res;
@Override
public void add1(int a) {
res = a+1;
System.out.println("a+1=" + res);
}
@Override
public void add(int a) {
addArray.add(a);
if(addArray.size() == 2){
res = addArray.get(0)+addArray.get(1);
addArray.clear();
System.out.println("a+b=" + res);
}
res = -1;
System.out.println("还有数据包未传入");
}
@Override
public void addself(int a) {
res = a+a;
System.out.println("a+a=" + res);
}
@Override
public void square(int a) {
res = a*a;
System.out.println("a*a=" + res);
}
@Override
public int getRes() {
return res;
}
}
\ No newline at end of file
package top.ninwoo.test.transfer.impl;
import com.pitong.business.item.DataPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import top.ninwoo.bishe.starter.service.NetworkService;
import top.ninwoo.test.transfer.TransferService;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.List;
@Service
public class TransferServiceImpl implements TransferService {
@Value("${slot}")
private Long slot; //时隙值
@Autowired
private NetworkService networkService;
//转发函数,需要增加
@Override
public void transferPackage(DataPackage dataPackage, String nextHop, long startime) {
//获取目标节点ip
String app_name = nextHop;
System.out.println(app_name);
String IP = this.getIpByAppName(app_name);
System.out.println(IP);
//发送至目标
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();
}
}
}
//不应该有这个函数
public String getIpByAppName(String appName) {
List<String> ipList = networkService.getIpListByAppName(11111l, appName);
if(!ipList.isEmpty()){
String ip_tmp = ipList.get(0);
String[] split_list = ip_tmp.split("/");
return split_list[0];
}
return null;
}
}
\ No newline at end of file
bishe.app.app-name=joliu
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
targetIp=127.0.0.1
#targetIp=192.168.47.1
#eta=${eta}
#targetIp=${targetIp}
slot=20000
\ No newline at end of file
......@@ -3,23 +3,166 @@ 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 com.pitong.business.service.picPro.picImpl.*;
import com.pitong.business.service.transfer.FindService;
import com.pitong.business.service.transfer.TransferService;
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.*;
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;
import java.util.*;
@Service
@SpringBootApplication
public class Application implements ApplicationRunner {
@Autowired
private FindService findService;
@Autowired
private TransferService transferService;
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class)
.web(WebApplicationType.NONE) // .REACTIVE, .SERVLET
.bannerMode(Banner.Mode.OFF)
.run(args);
}
Picture[] pictures = new Picture[2];
@Override
public void run(ApplicationArguments args) {
ServerSocket serverSocket = null;
InputStream inputStream = null;
ObjectInputStream objectInputStream = null;
try {
serverSocket = new ServerSocket(2020);
while (true) {
//接收数据包
Socket client = serverSocket.accept();
inputStream = client.getInputStream();
objectInputStream = new ObjectInputStream(new BufferedInputStream(inputStream));
Object object = objectInputStream.readObject();
//收到数据包
DataPackage dataPackage = (DataPackage) object;
System.out.println("receive");
//构建新的数据包
DataPackage newDataPackage = dataPackage;
//得到本机路由表
String[] route = findService.findRoute(dataPackage.getCurrentSataHop(), dataPackage.getRoute());
int flag = 0;
//判断是否为该边的终点,如果是,进行函数计算并创建一个新的数据包,转发
if (dataPackage.getCurrentSataHop().equals(dataPackage.getDestinSataHop())) {
LinkedList<Picture> picPara = new LinkedList<>();
//此时为终点
String task = findService.findTask(dataPackage.getCurrentSataHop(), dataPackage.getTaskTable());
switch (task) {
case "binaryProcess":
picPara = new binaryProcess().picProcess(dataPackage.getPicture());
break;
case "cutProcess":
picPara = new cutProcess().picProcess(dataPackage.getPicture());
break;
case "greyProcess":
picPara = new greyProcess().picProcess(dataPackage.getPicture());
break;
case "mergePorcess":
if (flag==0){
pictures[flag] = dataPackage.getPicture();
flag =1;
continue;
}else {
pictures[flag] = dataPackage.getPicture();
flag =0;
}
picPara = new mergePorcess().picProcess(pictures);
break;
case "tailorProcess":
picPara = new tailorProcess().picProcess(dataPackage.getPicture());
break;
}
// System.out.println("res = "+ picProcess.getRes());
//res不等于-1,说明计算过程正常
// if (picProcess.getRes() != -1) {
/* //写入更新后的数据
newDataPackage.setData(picProcess.getRes());*/
//找到目的地卫星数组
String[] destinSataHops = findService.findDestinSataHops(dataPackage.getPathTable(), dataPackage.getCurrentSataHop());
if(destinSataHops[0].equals("nolast")){
System.out.println("运行完毕");
break;
}
for (String destinSataHop : destinSataHops) {
//设置目的地址
newDataPackage.setDestinSataHop(destinSataHop);
//设置下一跳地址
newDataPackage.setNextSataHop(findService.findNextHop(destinSataHop, route));
//设置本机地址
newDataPackage.setCurrentSataHop(dataPackage.getNextSataHop());
//创建时间
Date date = new Date();
long time = date.getTime();
//转发
newDataPackage.setPicture(picPara.removeFirst());
transferService.transferPackage(newDataPackage, newDataPackage.getNextSataHop(), time);
}
// }
} else {//仅作转发的节点
newDataPackage.setNextSataHop(findService.findNextHop(dataPackage.getDestinSataHop(), route));
newDataPackage.setCurrentSataHop(dataPackage.getNextSataHop());
//创建时间
Date date = new Date();
long time = date.getTime();
//转发
transferService.transferPackage(newDataPackage, newDataPackage.getNextSataHop(), time);
}
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace(); } finally {
try {
if (objectInputStream != null) {
objectInputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
if (serverSocket != null) {
serverSocket.close();
}
} catch (IOException e) {
e.printStackTrace(); }
}
}
}
/*
@Service
@SpringBootApplication
public class Application implements ApplicationRunner {
......@@ -152,3 +295,4 @@ public class Application implements ApplicationRunner {
}
}
}
*/
/*
package com.pitong.business.service;
import com.pitong.business.item.DataPackage;
......@@ -229,8 +230,10 @@ public class ServerService {
communicationToCloud("==========================");
System.out.println("transfer next exec sate:"+sequence.get(3));
System.out.println("==========================");
/*communicationToCloud("transmission success!");
communicationToCloud("==========================");*/
*/
/*communicationToCloud("transmission success!");
communicationToCloud("==========================");*//*
}
sendToCloud(list);
......@@ -242,10 +245,12 @@ public class ServerService {
try {
if (aDouble < 20000){
Thread.sleep(Math.round(aDouble-(l2 - currentime)));
}/*else {
}*/
/*else {
if ((l2 - currentime) < 20000)
Thread.sleep(Math.round(20000-(l2 - currentime)));
}*/
}*//*
} catch (InterruptedException e) {
e.printStackTrace();
}
......@@ -567,9 +572,11 @@ public class ServerService {
*/
/*
System.out.println("task total time: "+(l22-fun1time)+"ms");
System.out.println("=====================");*/
System.out.println("=====================");*//*
}
......@@ -614,7 +621,8 @@ public class ServerService {
}
private void sendToCloud(List<String> list) {
/*Socket ss = null;
*/
/*Socket ss = null;
try {
//ip来自云地址
ss = new Socket(cldurl, cldport);
......@@ -631,12 +639,14 @@ public class ServerService {
} catch (IOException e) {
e.printStackTrace();
}
}*/
}*//*
return;
}
private DataPackage combine(int number, int routeNumber, List<Integer> sequence, String loc, String file_path,
*/
/* 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);
......@@ -651,7 +661,8 @@ public class ServerService {
dataPackage.setRouteNumber(routeNumber);
dataPackage.setTranDelay(tranDelay);
return dataPackage;
}
}*//*
private void saveToFile(Picture picture, String file_path) {
byte[] pic_data = picture.getData();
......@@ -751,3 +762,4 @@ public class ServerService {
return null;
}
}
*/
package com.pitong.business.service;
package com.pitong.business.service.picPro;
import com.pitong.business.item.Picture;
import java.util.LinkedList;
public interface IPicProcess {
String in_file = "/pic/in.jpg";
String out_file = "/pic/out.jpg";
......@@ -11,5 +13,6 @@ public interface IPicProcess {
String out_file2 = "/pic/out2.jpg";
public void picProcess(Picture... pictures);
public LinkedList<Picture> picProcess(Picture... pictures);
}
package com.pitong.business.service.picImpl;
package com.pitong.business.service.picPro.picImpl;
import com.pitong.business.item.Picture;
import com.pitong.business.service.IPicProcess;
import com.pitong.business.service.picPro.IPicProcess;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import static com.pitong.business.service.saveFile.Save.loadPicture;
import static com.pitong.business.service.saveFile.Save.saveToFile;
public class binaryProcess implements IPicProcess {
public static ArrayList<Picture> picPara = new ArrayList<>();
public static LinkedList<Picture> picPara = new LinkedList<>();
@Override
public void picProcess(Picture... pictures) {
public LinkedList<Picture> picProcess(Picture... pictures) {
for (Picture picture:pictures){
saveToFile(picture,in_file);
}
......@@ -24,5 +25,6 @@ public class binaryProcess implements IPicProcess {
e.printStackTrace();
}
picPara.add(loadPicture(out_file));
return picPara;
}
}
package com.pitong.business.service.picImpl;
package com.pitong.business.service.picPro.picImpl;
import com.pitong.business.item.Picture;
import com.pitong.business.service.IPicProcess;
import com.pitong.business.service.picPro.IPicProcess;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import static com.pitong.business.service.saveFile.Save.*;
public class cutProcess implements IPicProcess {
public static ArrayList<Picture> picPara = new ArrayList<>();
public static LinkedList<Picture> picPara = new LinkedList<>();
@Override
public void picProcess(Picture... pictures) {
public LinkedList<Picture> picProcess(Picture... pictures) {
for (Picture picture:pictures){
saveToFile(picture,in_file);
}
......@@ -25,5 +26,6 @@ public class cutProcess implements IPicProcess {
}
picPara.add(loadPicture(out_file1));
picPara.add(loadPicture(out_file2));
return picPara;
}
}
package com.pitong.business.service.picImpl;
package com.pitong.business.service.picPro.picImpl;
import com.pitong.business.item.Picture;
import com.pitong.business.service.IPicProcess;
import com.pitong.business.service.picPro.IPicProcess;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import static com.pitong.business.service.saveFile.Save.loadPicture;
import static com.pitong.business.service.saveFile.Save.saveToFile;
public class greyProcess implements IPicProcess {
public static ArrayList<Picture> picPara = new ArrayList<>();
public static LinkedList<Picture> picPara = new LinkedList<>();
@Override
public void picProcess(Picture... pictures) {
public LinkedList<Picture> picProcess(Picture... pictures) {
for (Picture picture:pictures){
saveToFile(picture,in_file);
}
......@@ -24,5 +25,6 @@ public class greyProcess implements IPicProcess {
e.printStackTrace();
}
picPara.add(loadPicture(out_file));
return picPara;
}
}
package com.pitong.business.service.picImpl;
package com.pitong.business.service.picPro.picImpl;
import com.pitong.business.item.Picture;
import com.pitong.business.service.IPicProcess;
import com.pitong.business.service.picPro.IPicProcess;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import static com.pitong.business.service.saveFile.Save.loadPicture;
import static com.pitong.business.service.saveFile.Save.saveToFile;
public class mergePorcess implements IPicProcess {
public static ArrayList<Picture> picPara = new ArrayList<>();
public static LinkedList<Picture> picPara = new LinkedList<>();
@Override
public void picProcess(Picture... pictures) {
public LinkedList<Picture> picProcess(Picture... pictures) {
saveToFile(pictures[0],in_file1);
saveToFile(pictures[1],in_file2);
try {
......@@ -23,5 +23,6 @@ public class mergePorcess implements IPicProcess {
e.printStackTrace();
}
picPara.add(loadPicture(out_file));
return picPara;
}
}
package com.pitong.business.service.picImpl;
package com.pitong.business.service.picPro.picImpl;
import com.pitong.business.item.Picture;
import com.pitong.business.service.IPicProcess;
import com.pitong.business.service.picPro.IPicProcess;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import static com.pitong.business.service.saveFile.Save.loadPicture;
import static com.pitong.business.service.saveFile.Save.saveToFile;
public class tailorProcess implements IPicProcess {
public static ArrayList<Picture> picPara = new ArrayList<>();
public static LinkedList<Picture> picPara = new LinkedList<>();
@Override
public void picProcess(Picture... pictures) {
public LinkedList<Picture> picProcess(Picture... pictures) {
for (Picture picture:pictures){
saveToFile(picture,in_file);
}
......@@ -24,5 +24,7 @@ public class tailorProcess implements IPicProcess {
e.printStackTrace();
}
picPara.add(loadPicture(out_file));
return picPara;
}
}
package com.pitong.business.service.transfer;
import java.util.concurrent.ConcurrentHashMap;
/**
* 发现路由
*/
public interface FindService{
/**
* 根据路径表,找到本机需要处理路径条数
* c->a ==> sata1->sata3
*/
String[] findDestinSataHops(String[] pathTable, String currenthop);
/**
* 根据本机卫星名,全局路由表,路由表得到本机路由表
*/
String[] findRoute(String currentSataHo, String[][] routeTable);
/**
* 根据目的卫星名,本机路由表找到下一跳卫星名
*/
String findNextHop(String destinSataHop, String[] route);
/**
* 找到本机的任务
*/
String findTask(String currenSataHop, ConcurrentHashMap<String, String> taskMap);
}
\ No newline at end of file
package com.pitong.business.service.transfer;
/**
* 功能函数:灰度,二值。。。
*/
public interface FunctionService {
//Sample:建议取0~9整数
void add1(int a);
void add(int a);
void addself(int a);
void square(int a);
int getRes();
}
\ No newline at end of file
package com.pitong.business.service.transfer;
import com.pitong.business.item.DataPackage;
/**
* 转发数据包
*/
public interface TransferService {
void transferPackage(DataPackage dataPackage, String nextHop, long startime);
}
package com.pitong.business.service.transfer.impl;
import com.pitong.business.service.transfer.FindService;
import org.springframework.stereotype.Service;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class FindServiceImpl implements FindService {
@Override
public String[] findDestinSataHops(String[] pathTable,String currenthop) {
String[] destinSataHops = new String[]{};
int j = 0;
if(pathTable.length == 0){
System.out.println("路径表为空");
destinSataHops[0] = "nopara";
return destinSataHops;
}
for (int i = 0; i < pathTable.length; i++) {
//判断本机是否为路径起点
if(currenthop.equals(pathTable[i].split("->")[0])){
destinSataHops[j++] = pathTable[i].split("->")[1];
}
}
if(destinSataHops.length == 0){
destinSataHops[0] = "nolast";
}
return destinSataHops;
}
@Override
public String[] findRoute(String currentSataHop,String[][] routeTable) {
//判断路由表是否存在
if(routeTable.length == 0){
System.out.println("路由表为空");
return null;
}
//找到本机路由表
String[] route = this.findCurrentRoute(currentSataHop,routeTable);
return route;
}
@Override
public String findNextHop(String destinSataHop, String[] route) {
int index = Integer.parseInt(destinSataHop.split("sate")[1]);
String nextHop = route[index-1];
return nextHop;
}
@Override
public String findTask(String currenSataHop, ConcurrentHashMap<String, String> taskMap) {
if(taskMap.isEmpty()){
System.out.println("无任务表");
return null;
}
return taskMap.get(currenSataHop);
}
//找到本卫星的路由
private String[] findCurrentRoute(String sataname, String[][] routeTable){
int index = Integer.parseInt(sataname.split("sate")[1]);
return routeTable[index-1];
}
}
package com.pitong.business.service.transfer.impl;
import com.pitong.business.service.transfer.FunctionService;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@Service
public class FunctionServiceImpl implements FunctionService {
private ArrayList<Integer> addArray = new ArrayList<>();
private int res;
@Override
public void add1(int a) {
res = a+1;
System.out.println("a+1=" + res);
}
@Override
public void add(int a) {
addArray.add(a);
if(addArray.size() == 2){
res = addArray.get(0)+addArray.get(1);
addArray.clear();
System.out.println("a+b=" + res);
}
res = -1;
System.out.println("还有数据包未传入");
}
@Override
public void addself(int a) {
res = a+a;
System.out.println("a+a=" + res);
}
@Override
public void square(int a) {
res = a*a;
System.out.println("a*a=" + res);
}
@Override
public int getRes() {
return res;
}
}
\ No newline at end of file
package com.pitong.business.service.transfer.impl;
import com.pitong.business.item.DataPackage;
import com.pitong.business.service.transfer.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import top.ninwoo.bishe.starter.service.NetworkService;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.List;
@Service
public class TransferServiceImpl implements TransferService {
@Value("${slot}")
private Long slot; //时隙值
@Autowired
private NetworkService networkService;
//转发函数,需要增加
@Override
public void transferPackage(DataPackage dataPackage, String nextHop, long startime) {
//获取目标节点ip
String app_name = nextHop;
System.out.println(app_name);
String IP = this.getIpByAppName(app_name);
System.out.println(IP);
//发送至目标
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();
}
}
}
//不应该有这个函数
public String getIpByAppName(String appName) {
List<String> ipList = networkService.getIpListByAppName(11111l, appName);
if(!ipList.isEmpty()){
String ip_tmp = ipList.get(0);
String[] split_list = ip_tmp.split("/");
return split_list[0];
}
return null;
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ bishe:
cloud-url: 192.168.31.198:9091
# cloud-url: 192.168.31.198:9090
slot: 20000 # 1000L*20
coe: 0.7
cldUrl: 192.168.31.198
cldPort: 8900
slot=20000
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