Commit 022c4d21 authored by Elf's avatar Elf

8-19

parent 16b2a979
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cnf</artifactId>
<groupId>top.ninwoo</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cnf-path</artifactId>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-client-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package top.ninwoo.app.pathcompute.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
//数据包中包含的东西
//todo 未加任务表和路径表
@Data
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;
}
package top.ninwoo.app.pathcompute.entity;
import lombok.Data;
import java.io.Serializable;
@Data
public class Picture implements Serializable {
private byte[] data;
}
\ No newline at end of file
package top.ninwoo.app.pathcompute.service;
/**
* 功能函数:灰度,二值。。。
*/
public interface Function {
//Sample:建议取0~9整数
int add(int a,int b);
int multiply(int a,int b);
int square(int a);
}
package top.ninwoo.app.pathcompute.service;
import top.ninwoo.app.pathcompute.entity.DataPackage;
/**
* 转发数据包
*/
public interface Transfer {
void transferPackage(DataPackage dataPackage, int nextHop, long startime);
}
package top.ninwoo.app.pathcompute.service.impl;
import top.ninwoo.app.pathcompute.service.Function;
public class FunctionImpl implements Function {
@Override
public int add(int a, int b) {
return a+b;
}
@Override
public int multiply(int a, int b) {
return a*b;
}
@Override
public int square(int a) {
return a*a;
}
}
package top.ninwoo.app.pathcompute.service.impl;
import org.springframework.beans.factory.annotation.Value;
import top.ninwoo.app.pathcompute.entity.DataPackage;
import top.ninwoo.app.pathcompute.service.Transfer;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
public class TransferImpl implements Transfer {
@Value("${slot}")
private Long slot; //时隙值
@Override
public 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();
}
}
}
}
bishe:
app:
app-name: joliu
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
......@@ -20,6 +20,7 @@
<module>apps/cnf-weixingsim</module>
<module>apps/cnf-case-dis</module>
<module>apps/cnf-app-demo</module>
<module>apps/cnf-path</module>
</modules>
......
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