Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Distributed Computing and Network Fusion System
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WirelessInformationCollaborate
Distributed Computing and Network Fusion System
Commits
d65fc545
Commit
d65fc545
authored
Aug 25, 2020
by
Elf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
转发测试完成
parent
022c4d21
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
781 additions
and
75 deletions
+781
-75
apps/cnf-api/pom.xml
apps/cnf-api/pom.xml
+27
-0
apps/cnf-api/src/main/java/top/ninwoo/app/api/DataPackage.java
...cnf-api/src/main/java/top/ninwoo/app/api/DataPackage.java
+27
-0
apps/cnf-path/pom.xml
apps/cnf-path/pom.xml
+6
-0
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/Pathmain.java
...th/src/main/java/top/ninwoo/app/pathcompute/Pathmain.java
+133
-0
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/entity/DataPackage.java
...n/java/top/ninwoo/app/pathcompute/entity/DataPackage.java
+0
-27
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/entity/Picture.java
.../main/java/top/ninwoo/app/pathcompute/entity/Picture.java
+0
-12
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/FindService.java
.../java/top/ninwoo/app/pathcompute/service/FindService.java
+28
-0
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/FunctionService.java
...a/top/ninwoo/app/pathcompute/service/FunctionService.java
+14
-0
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/TransferService.java
...a/top/ninwoo/app/pathcompute/service/TransferService.java
+11
-0
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/FindServiceImpl.java
.../ninwoo/app/pathcompute/service/impl/FindServiceImpl.java
+67
-0
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/FunctionImpl.java
...top/ninwoo/app/pathcompute/service/impl/FunctionImpl.java
+0
-20
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/FunctionServiceImpl.java
...woo/app/pathcompute/service/impl/FunctionServiceImpl.java
+46
-0
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/TransferServiceImpl.java
...woo/app/pathcompute/service/impl/TransferServiceImpl.java
+27
-6
apps/cnf-path/src/main/resources/application.yaml
apps/cnf-path/src/main/resources/application.yaml
+4
-5
apps/cnf-planning/pom.xml
apps/cnf-planning/pom.xml
+63
-0
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/Planning.java
...g/src/main/java/top/ninwoo/app/pathplanning/Planning.java
+68
-0
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/FindService.java
...java/top/ninwoo/app/pathplanning/service/FindService.java
+27
-0
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/FunctionService.java
.../top/ninwoo/app/pathplanning/service/FunctionService.java
+14
-0
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/TransferService.java
.../top/ninwoo/app/pathplanning/service/TransferService.java
+12
-0
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/impl/FindServiceImpl.java
...ninwoo/app/pathplanning/service/impl/FindServiceImpl.java
+67
-0
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/impl/FunctionServiceImpl.java
...oo/app/pathplanning/service/impl/FunctionServiceImpl.java
+47
-0
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/impl/TransferServiceImpl.java
...oo/app/pathplanning/service/impl/TransferServiceImpl.java
+75
-0
apps/cnf-planning/src/main/resources/application.yaml
apps/cnf-planning/src/main/resources/application.yaml
+7
-0
apps/cnf-weixingsim/src/main/resources/application.properties
.../cnf-weixingsim/src/main/resources/application.properties
+2
-0
apps/cnf-weixingsim/src/test/java/top/ninwoo/WxTests.java
apps/cnf-weixingsim/src/test/java/top/ninwoo/WxTests.java
+7
-5
pom.xml
pom.xml
+2
-0
No files found.
apps/cnf-api/pom.xml
0 → 100644
View file @
d65fc545
<?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-api
</artifactId>
<packaging>
jar
</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
apps/cnf-api/src/main/java/top/ninwoo/app/api/DataPackage.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.api
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.concurrent.ConcurrentHashMap
;
//数据包中包含的东西
@Data
public
class
DataPackage
implements
Serializable
{
//加入任务表:ConcurrentHashMap<卫星名字,功能函数名>
private
ConcurrentHashMap
<
String
,
String
>
taskTable
=
new
ConcurrentHashMap
<>();
//加入路径表:String[]
private
String
[]
pathTable
=
new
String
[]{};
//全局路由表
private
String
[][]
route
=
new
String
[][]{};
//本机卫星名
private
String
currentSataHop
;
//下一跳卫星名
private
String
nextSataHop
;
//该条路径的目的卫星名
private
String
destinSataHop
;
//数据,仅作测试用
private
int
data
;
}
apps/cnf-path/pom.xml
View file @
d65fc545
...
...
@@ -35,6 +35,12 @@
<groupId>
org.influxdb
</groupId>
<artifactId>
influxdb-java
</artifactId>
</dependency>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
cnf-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<build>
...
...
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/Pathmain.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathcompute
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.api.DataPackage
;
import
top.ninwoo.app.pathcompute.service.FindService
;
import
top.ninwoo.app.pathcompute.service.FunctionService
;
import
top.ninwoo.app.pathcompute.service.TransferService
;
import
java.io.BufferedInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.ObjectInputStream
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.ArrayList
;
import
java.util.Date
;
@Service
@SpringBootApplication
public
class
Pathmain
implements
ApplicationRunner
{
@Autowired
private
FindService
findService
;
@Autowired
private
FunctionService
functionService
;
@Autowired
private
TransferService
transferService
;
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
Pathmain
.
class
)
.
web
(
WebApplicationType
.
NONE
)
// .REACTIVE, .SERVLET
.
bannerMode
(
Banner
.
Mode
.
OFF
)
.
run
(
args
);
}
@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
());
//判断是否为该边的终点,如果是,进行函数计算并创建一个新的数据包,转发
if
(
dataPackage
.
getCurrentSataHop
().
equals
(
dataPackage
.
getDestinSataHop
()))
{
//此时为终点
String
task
=
findService
.
findTask
(
dataPackage
.
getCurrentSataHop
(),
dataPackage
.
getTaskTable
());
switch
(
task
)
{
case
"add1"
:
functionService
.
add1
(
dataPackage
.
getData
());
break
;
case
"add"
:
functionService
.
add
(
dataPackage
.
getData
());
break
;
case
"addself"
:
functionService
.
addself
(
dataPackage
.
getData
());
break
;
case
"square"
:
functionService
.
square
(
dataPackage
.
getData
());
break
;
}
System
.
out
.
println
(
"res = "
+
functionService
.
getRes
());
//res不等于-1,说明计算过程正常
if
(
functionService
.
getRes
()
!=
-
1
)
{
//写入更新后的数据
newDataPackage
.
setData
(
functionService
.
getRes
());
//找到目的地卫星数组
ArrayList
<
String
>
destinSataHops
=
findService
.
findDestinSataHops
(
dataPackage
.
getPathTable
(),
dataPackage
.
getCurrentSataHop
());
if
(
destinSataHops
.
get
(
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
();
//转发
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
();
}
}
}
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/entity/DataPackage.java
deleted
100644 → 0
View file @
022c4d21
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
;
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/entity/Picture.java
deleted
100644 → 0
View file @
022c4d21
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
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/FindService.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathcompute.service
;
import
java.util.ArrayList
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* 发现路由
*/
public
interface
FindService
{
/**
* 根据路径表,找到本机需要处理路径条数
* c->a ==> sata1->sata3
*/
ArrayList
<
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
);
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/Function.java
→
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/Function
Service
.java
View file @
d65fc545
package
top.ninwoo.app.pathcompute.service
;
/**
* 功能函数:灰度,二值。。。
*/
public
interface
Function
{
public
interface
Function
Service
{
//Sample:建议取0~9整数
int
add
(
int
a
,
int
b
);
int
multiply
(
int
a
,
int
b
);
int
square
(
int
a
);
void
add1
(
int
a
);
void
add
(
int
a
);
void
addself
(
int
a
);
void
square
(
int
a
);
int
getRes
();
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/Transfer.java
→
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/Transfer
Service
.java
View file @
d65fc545
package
top.ninwoo.app.pathcompute.service
;
import
top.ninwoo.app.
pathcompute.entity
.DataPackage
;
import
top.ninwoo.app.
api
.DataPackage
;
/**
* 转发数据包
*/
public
interface
Transfer
{
public
interface
Transfer
Service
{
void
transferPackage
(
DataPackage
dataPackage
,
int
nextHop
,
long
startime
);
void
transferPackage
(
DataPackage
dataPackage
,
String
nextHop
,
long
startime
);
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/FindServiceImpl.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathcompute.service.impl
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.pathcompute.service.FindService
;
import
java.util.ArrayList
;
import
java.util.concurrent.ConcurrentHashMap
;
@Service
public
class
FindServiceImpl
implements
FindService
{
@Override
public
ArrayList
<
String
>
findDestinSataHops
(
String
[]
pathTable
,
String
currenthop
)
{
ArrayList
<
String
>
destinSataHops
=
new
ArrayList
<>();
int
j
=
0
;
if
(
pathTable
.
length
==
0
){
System
.
out
.
println
(
"路径表为空"
);
destinSataHops
.
add
(
"nopara"
);
return
destinSataHops
;
}
for
(
int
i
=
0
;
i
<
pathTable
.
length
;
i
++)
{
//判断本机是否为路径起点
if
(
currenthop
.
equals
(
pathTable
[
i
].
split
(
"->"
)[
0
])){
destinSataHops
.
add
(
j
++,
pathTable
[
i
].
split
(
"->"
)[
1
]);
}
}
if
(
destinSataHops
.
size
()
==
0
){
destinSataHops
.
add
(
"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
(
"sata"
)[
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
(
"sata"
)[
1
]);
return
routeTable
[
index
-
1
];
}
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/FunctionImpl.java
deleted
100644 → 0
View file @
022c4d21
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
;
}
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/FunctionServiceImpl.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathcompute.service.impl
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.pathcompute.service.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
;
}
}
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/TransferImpl.java
→
apps/cnf-path/src/main/java/top/ninwoo/app/pathcompute/service/impl/Transfer
Service
Impl.java
View file @
d65fc545
package
top.ninwoo.app.pathcompute.service.impl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
top.ninwoo.app.pathcompute.entity.DataPackage
;
import
top.ninwoo.app.pathcompute.service.Transfer
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.api.DataPackage
;
import
top.ninwoo.app.pathcompute.service.TransferService
;
import
top.ninwoo.bishe.starter.service.NetworkService
;
import
java.io.IOException
;
import
java.io.ObjectOutputStream
;
import
java.net.Socket
;
import
java.util.List
;
public
class
TransferImpl
implements
Transfer
{
@Service
public
class
TransferServiceImpl
implements
TransferService
{
@Value
(
"${slot}"
)
private
Long
slot
;
//时隙值
@Autowired
private
NetworkService
networkService
;
//转发函数,需要增加
@Override
public
void
transferPackage
(
DataPackage
dataPackage
,
int
nextHop
,
long
startime
)
{
public
void
transferPackage
(
DataPackage
dataPackage
,
String
nextHop
,
long
startime
)
{
//获取目标节点ip
String
app_name
=
"sate"
+
nextHop
;
String
IP
=
ipService
.
getIpByAppName
(
app_name
);
String
app_name
=
nextHop
;
String
IP
=
this
.
getIpByAppName
(
app_name
);
//发送至目标
send
(
dataPackage
,
IP
,
2020
,
startime
);
}
//发送数据包
private
void
send
(
DataPackage
dataPackage
,
String
ip
,
int
port
,
Long
startime
)
{
Socket
socket
=
null
;
try
{
...
...
@@ -49,4 +59,15 @@ public class TransferImpl implements Transfer {
}
}
}
//不应该有这个函数
public
String
getIpByAppName
(
String
appName
)
{
List
<
String
>
ipList
=
networkService
.
getIpListByAppName
(
11111
l
,
appName
);
if
(!
ipList
.
isEmpty
()){
String
ip_tmp
=
ipList
.
get
(
0
);
String
[]
split_list
=
ip_tmp
.
split
(
"/"
);
return
split_list
[
0
];
}
return
null
;
}
}
apps/cnf-path/src/main/resources/application.yaml
View file @
d65fc545
bishe
:
app
:
app-name
:
joliu
cloud-url
:
192.168.31.198:9091
# cloud-url: 192.168.31.198:9090
cloud-url
:
192.168.190.135:9091
zookeeper-url
:
192.168.190.135:2181
slot
:
20000
# 1000L*20
coe
:
0.7
cldUrl
:
192.168.31.198
cldPort
:
8900
apps/cnf-planning/pom.xml
0 → 100644
View file @
d65fc545
<?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-planning
</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>
<dependency>
<groupId>
top.ninwoo
</groupId>
<artifactId>
cnf-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</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
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/Planning.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathplanning
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.Banner
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.api.DataPackage
;
import
top.ninwoo.app.pathplanning.service.TransferService
;
import
java.util.Date
;
@Service
@SpringBootApplication
public
class
Planning
implements
ApplicationRunner
{
@Autowired
private
TransferService
transferService
;
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
Planning
.
class
)
.
web
(
WebApplicationType
.
NONE
)
// .REACTIVE, .SERVLET
.
bannerMode
(
Banner
.
Mode
.
OFF
)
.
run
(
args
);
}
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
Date
date
=
new
Date
();
long
time
=
date
.
getTime
();
DataPackage
dataPackage
=
new
DataPackage
();
//任务表
dataPackage
.
getTaskTable
().
put
(
"sata1"
,
"add1"
);
dataPackage
.
getTaskTable
().
put
(
"sata3"
,
"addself"
);
dataPackage
.
getTaskTable
().
put
(
"sata2"
,
"square"
);
dataPackage
.
getTaskTable
().
put
(
"sata5"
,
"add"
);
//路径表
String
[]
path
=
new
String
[]{
"sata1->sata2"
,
"sata1->sata3"
,
"sata2->sata5"
,
"sata3->sata5"
,
//sata5这里设置为最后一个节点
};
dataPackage
.
setPathTable
(
path
);
//全局路由表
String
[][]
route
=
new
String
[][]{
{
"sata1"
,
"sata2"
,
"sata3"
,
"sata2"
,
"sata3"
},
{
"sata1"
,
"sata2"
,
"sata3"
,
"sata4"
,
"sata3"
},
{
"sata1"
,
"sata2"
,
"sata3"
,
"sata2"
,
"sata5"
},
{
"sata2"
,
"sata2"
,
"sata2"
,
"sata4"
,
"sata2"
},
{
"sata3"
,
"sata3"
,
"sata3"
,
"sata3"
,
"sata5"
},
};
dataPackage
.
setRoute
(
route
);
dataPackage
.
setCurrentSataHop
(
"sata1"
);
dataPackage
.
setNextSataHop
(
"sata1"
);
dataPackage
.
setDestinSataHop
(
"sata1"
);
dataPackage
.
setData
(
4
);
transferService
.
transferPackage
(
dataPackage
,
dataPackage
.
getCurrentSataHop
(),
time
);
System
.
out
.
println
(
"send sucess"
);
}
}
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/FindService.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathplanning.service
;
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
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/FunctionService.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathplanning.service
;
/**
* 功能函数:灰度,二值。。。
*/
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
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/TransferService.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathplanning.service
;
import
top.ninwoo.app.api.DataPackage
;
/**
* 转发数据包
*/
public
interface
TransferService
{
void
transferPackage
(
DataPackage
dataPackage
,
String
nextHop
,
long
startime
);
}
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/impl/FindServiceImpl.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathplanning.service.impl
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.pathplanning.service.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
(
"sata"
)[
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
(
"sata"
)[
1
]);
return
routeTable
[
index
-
1
];
}
}
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/impl/FunctionServiceImpl.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathplanning.service.impl
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.pathplanning.service.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
apps/cnf-planning/src/main/java/top/ninwoo/app/pathplanning/service/impl/TransferServiceImpl.java
0 → 100644
View file @
d65fc545
package
top.ninwoo.app.pathplanning.service.impl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
top.ninwoo.app.api.DataPackage
;
import
top.ninwoo.app.pathplanning.service.TransferService
;
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
(
11111
l
,
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
apps/cnf-planning/src/main/resources/application.yaml
0 → 100644
View file @
d65fc545
bishe
:
app
:
app-name
:
joliu
cloud-url
:
192.168.190.135:9091
zookeeper-url
:
192.168.190.135:2181
slot
:
20000
# 1000L*20
apps/cnf-weixingsim/src/main/resources/application.properties
0 → 100644
View file @
d65fc545
bishe.app.app-name
=
joliu
bishe.app.cloud-url
=
192.168.190.135:9091
\ No newline at end of file
apps/cnf-weixingsim/src/test/java/top/ninwoo/WxTests.java
View file @
d65fc545
...
...
@@ -35,7 +35,7 @@ public class WxTests {
ArrayList
<
SeparatedClusterConfig
>
clusterConfigs
=
new
ArrayList
<>();
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.190.135:
8081
"
);
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.190.135:
18088
"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"joliu"
);
...
...
@@ -329,17 +329,17 @@ public class WxTests {
SeparatedClusterConfig
separatedClusterConfig
=
new
SeparatedClusterConfig
();
List
<
ContainerDescription
>
cds
=
new
ArrayList
<>();
// TODO: 这个ID应该是从借口获取的
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.190.135:
8081
"
);
separatedClusterConfig
.
setEdgeNodeId
(
"192.168.190.135:
18088
"
);
ClusterConfig
clusterConfig
=
new
ClusterConfig
();
clusterConfig
.
setId
(
11111
l
);
clusterConfig
.
setOwner
(
"
joliu
"
);
clusterConfig
.
setOwner
(
"
liujo
"
);
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
tp
.
delHistory
();
File
file
=
new
File
(
"C:\\WorkSpace\\
test
\\topusim_1.txt"
);
File
file
=
new
File
(
"C:\\WorkSpace\\
TXT
\\topusim_1.txt"
);
List
<
WeiXingData
>
wxData
=
wx
.
iniTopo
(
file
);
int
[][]
toponet
=
tp
.
getTopology
(
wxData
,
sd
);
...
...
@@ -353,7 +353,7 @@ public class WxTests {
DockerContainer
container
=
new
DockerContainer
();
container
.
setName
(
wxData
.
get
(
k
).
getName
());
container
.
setCommand
(
"sh"
);
container
.
setImage
(
"
joliu/networktest
"
);
container
.
setImage
(
"
path
"
);
containerDescription
.
setDockerContainer
(
container
);
cds
.
add
(
containerDescription
);
...
...
@@ -374,6 +374,7 @@ public class WxTests {
//下发逻辑拓扑
clusterService
.
sendLogicTopoToEdgeNode
(
clusterConfigs
);
/*
for (int i = 1; ; i++) {
Thread.sleep(2000);
int time = i * sd.getJiange();
...
...
@@ -386,6 +387,7 @@ public class WxTests {
clusterService.adjustLogicTopoToEdgeNode(clusterConfigs);
}
*/
}
//测试容器运行程序
...
...
pom.xml
View file @
d65fc545
...
...
@@ -21,6 +21,8 @@
<module>
apps/cnf-case-dis
</module>
<module>
apps/cnf-app-demo
</module>
<module>
apps/cnf-path
</module>
<module>
apps/cnf-planning
</module>
<module>
apps/cnf-api
</module>
</modules>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment