Commit 6a1f8be3 authored by Hu Jintao's avatar Hu Jintao

测试转发功能融合

parent e5b5eadb
package com.pitong.business.item;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import lombok.Data;
......
......@@ -61,7 +61,7 @@ public class BisheTestMain implements ApplicationRunner {
int[] result = doMap.result;
boolean flag = repetition(result);
while (result[0] == 0 || flag){
System.out.println("failure mapping :"+Arrays.toString(result));
// System.out.println("failure mapping :"+Arrays.toString(result));
doMap.doMapApp(link,func);
result = doMap.result;
flag = repetition(result);
......@@ -96,7 +96,7 @@ public class BisheTestMain implements ApplicationRunner {
System.out.println("========================================");
System.out.println();
String file_path = "passport.jpg";
String file_path = "C:\\Users\\225\\Pictures\\Camera Roll\\passport.jpg";
Picture picture = loadPicture(file_path);
dataPackage.setPicture(picture);
dataPackage.setCurrentSataHop("sate1");
......
......@@ -133,9 +133,9 @@ 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(1 / best_par.fit);
System.out.println(Arrays.toString(best_par.task));
System.out.println(Arrays.toString(best_par.taskfinal));
System.out.println(Arrays.toString(best_par.taskfinal));*/
//赋值节点映射结果
int itemp = 0;
for (int a:best_par.taskfinal
......@@ -143,7 +143,7 @@ public class DoMap {
result[itemp++] = (a)+1;
//result[itemp++] = (a%num)+1;
}
System.out.println("optimal mapping scheme"+Arrays.toString(result));
// 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]);
......@@ -555,7 +555,9 @@ public class DoMap {
private void isRepitition(int[] task) {
for (int i = 1;i<task.length-1;i++){
for (int j = i+1;j<task.length-1;j++){
if (task[i]==task[j] && task[j]%30<29) task[j]+=1;
if (task[i]==task[j] && task[j]%dev<29) {
task[j]+=1;
}
}
}
}
......
......@@ -4,10 +4,7 @@ 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);
// String[] strings = new String[];
// strings[0] = "1";
}
}
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.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
......@@ -27,7 +27,7 @@ public class TransferServiceImpl implements TransferService {
//获取目标节点ip
String app_name = nextHop;
System.out.println(app_name);
String IP = this.getIpByAppName(app_name);
String IP = "127.0.0.1";//this.getIpByAppName(app_name);
System.out.println(IP);
//发送至目标
send(dataPackage, IP, 2020, startime);
......
......@@ -93,8 +93,8 @@ public class Application implements ApplicationRunner {
newDataPackage.setData(picProcess.getRes());*/
//找到目的地卫星数组
String[] destinSataHops = findService.findDestinSataHops(dataPackage.getPathTable(), dataPackage.getCurrentSataHop());
if(destinSataHops[0].equals("nolast")){
ArrayList<String> destinSataHops = findService.findDestinSataHops(dataPackage.getPathTable(), dataPackage.getCurrentSataHop());
if(destinSataHops.get(0).equals("nolast")){
System.out.println("运行完毕");
break;
}
......
package com.pitong.business.service.transfer;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -11,7 +12,7 @@ public interface FindService{
* 根据路径表,找到本机需要处理路径条数
* c->a ==> sata1->sata3
*/
String[] findDestinSataHops(String[] pathTable, String currenthop);
ArrayList<String> findDestinSataHops(String[] pathTable, String currenthop);
/**
* 根据本机卫星名,全局路由表,路由表得到本机路由表
*/
......
......@@ -3,28 +3,35 @@ package com.pitong.business.service.transfer.impl;
import com.pitong.business.service.transfer.FindService;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class FindServiceImpl implements FindService {
@Override
public String[] findDestinSataHops(String[] pathTable,String currenthop) {
String[] destinSataHops = new String[]{};
public ArrayList<String> findDestinSataHops(String[] pathTable,String currenthop) {
ArrayList<String> destinSataHops = new ArrayList<>();
int j = 0;
if(pathTable.length == 0){
System.out.println("路径表为空");
destinSataHops[0] = "nopara";
destinSataHops.add(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];
/* System.out.println(Arrays.toString(pathTable));
System.out.println();
System.out.println(currenthop);
System.out.println("destinSataHops index"+j);
System.out.println("pathTable[i].split(\"->\")[1]"+pathTable[i].split("->")[1]);*/
destinSataHops.add(j++,pathTable[i].split("->")[1]);
}
}
if(destinSataHops.length == 0){
destinSataHops[0] = "nolast";
if(destinSataHops.size() == 0){
destinSataHops.add("nolast");
}
return destinSataHops;
}
......
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