mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-24 00:03:09 +01:00
add dist_noAC
This commit is contained in:
parent
919d13baa3
commit
7ec7ecde6b
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@ -33,6 +33,16 @@
|
|||||||
"buildFlags": "-tags 'novpp'",
|
"buildFlags": "-tags 'novpp'",
|
||||||
"env": {"CGO_CFLAGS":"-I/usr/include/memif"},
|
"env": {"CGO_CFLAGS":"-I/usr/include/memif"},
|
||||||
"args":["-config","example_config/p2p_mode/genp2p.yaml","-mode","gencfg","-cfgmode","p2p"/*,"-example"*/],
|
"args":["-config","example_config/p2p_mode/genp2p.yaml","-mode","gencfg","-cfgmode","p2p"/*,"-example"*/],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Launch Slove",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${workspaceFolder}",
|
||||||
|
"buildFlags": "-tags 'novpp'",
|
||||||
|
"env": {"CGO_CFLAGS":"-I/usr/include/memif"},
|
||||||
|
"args":["-config","example_config/static_mode/path.txt","-mode","solve"],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -174,7 +174,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
|
|||||||
g.UpdateLatency(3, 5, 0.5, 99999, 0, false, false)
|
g.UpdateLatency(3, 5, 0.5, 99999, 0, false, false)
|
||||||
g.UpdateLatency(6, 4, 0.5, 99999, 0, false, false)
|
g.UpdateLatency(6, 4, 0.5, 99999, 0, false, false)
|
||||||
g.UpdateLatency(4, 6, 0.5, 99999, 0, false, false)
|
g.UpdateLatency(4, 6, 0.5, 99999, 0, false, false)
|
||||||
_, next, _ := g.FloydWarshall(false)
|
_, _, next, _ := g.FloydWarshall(false)
|
||||||
econfig.NextHopTable = next
|
econfig.NextHopTable = next
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -154,7 +154,7 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
|
|||||||
NMCfg.EdgeNode.MacPrefix = fmt.Sprintf("%02X:%02X:%02X:%02X", pbyte[0], pbyte[1], pbyte[2], pbyte[3])
|
NMCfg.EdgeNode.MacPrefix = fmt.Sprintf("%02X:%02X:%02X:%02X", pbyte[0], pbyte[1], pbyte[2], pbyte[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
dist, next, err := g.FloydWarshall(false)
|
dist, dist_noAC, next, err := g.FloydWarshall(false)
|
||||||
g.SetNHTable(next)
|
g.SetNHTable(next)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
@ -164,6 +164,7 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
|
|||||||
fmt.Println(string(nhTableStr))
|
fmt.Println(string(nhTableStr))
|
||||||
}
|
}
|
||||||
all_vert := g.Vertices()
|
all_vert := g.Vertices()
|
||||||
|
fmt.Printf("Distance With Additional Cost\n")
|
||||||
if NMCfg.DistanceMatrix != "" {
|
if NMCfg.DistanceMatrix != "" {
|
||||||
for u := range all_vert {
|
for u := range all_vert {
|
||||||
for v := range all_vert {
|
for v := range all_vert {
|
||||||
@ -177,6 +178,20 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Distance Without Additional Cost\n")
|
||||||
|
if NMCfg.DistanceMatrix != "" {
|
||||||
|
for u := range all_vert {
|
||||||
|
for v := range all_vert {
|
||||||
|
if u != v {
|
||||||
|
path, err := g.Path(u, v)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("couldn't find path from %v to %v: %v", u, v, err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%d -> %d\t%3f\t%v\n", u, v, dist_noAC[u][v], path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
econfig, err := GetExampleEdgeConf(NMCfg.EdgeConfigTemplate, false)
|
econfig, err := GetExampleEdgeConf(NMCfg.EdgeConfigTemplate, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if enableP2P {
|
if enableP2P {
|
||||||
|
@ -69,12 +69,13 @@ type HttpPeerLocalIP struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HttpState struct {
|
type HttpState struct {
|
||||||
PeerInfo map[mtypes.Vertex]HttpPeerInfo
|
PeerInfo map[mtypes.Vertex]HttpPeerInfo
|
||||||
Infinity float64
|
Infinity float64
|
||||||
Edges map[mtypes.Vertex]map[mtypes.Vertex]float64
|
Edges map[mtypes.Vertex]map[mtypes.Vertex]float64
|
||||||
Edges_Nh map[mtypes.Vertex]map[mtypes.Vertex]float64
|
Edges_Nh map[mtypes.Vertex]map[mtypes.Vertex]float64
|
||||||
NhTable mtypes.NextHopTable
|
NhTable mtypes.NextHopTable
|
||||||
Dist mtypes.DistTable
|
Dist mtypes.DistTable
|
||||||
|
Dist_noAC mtypes.DistTable
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpPeerInfo struct {
|
type HttpPeerInfo struct {
|
||||||
@ -563,12 +564,13 @@ func manage_get_peerstate(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer httpobj.RUnlock()
|
defer httpobj.RUnlock()
|
||||||
if time.Now().After(httpobj.http_StateExpire) {
|
if time.Now().After(httpobj.http_StateExpire) {
|
||||||
hs := HttpState{
|
hs := HttpState{
|
||||||
PeerInfo: make(map[mtypes.Vertex]HttpPeerInfo),
|
PeerInfo: make(map[mtypes.Vertex]HttpPeerInfo),
|
||||||
NhTable: httpobj.http_graph.GetNHTable(false),
|
NhTable: httpobj.http_graph.GetNHTable(false),
|
||||||
Infinity: mtypes.Infinity,
|
Infinity: mtypes.Infinity,
|
||||||
Edges: httpobj.http_graph.GetEdges(false, false),
|
Edges: httpobj.http_graph.GetEdges(false, false),
|
||||||
Edges_Nh: httpobj.http_graph.GetEdges(true, true),
|
Edges_Nh: httpobj.http_graph.GetEdges(true, true),
|
||||||
Dist: httpobj.http_graph.GetDtst(),
|
Dist: httpobj.http_graph.GetDtst(true),
|
||||||
|
Dist_noAC: httpobj.http_graph.GetDtst(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, peerinfo := range httpobj.http_sconfig.Peers {
|
for _, peerinfo := range httpobj.http_sconfig.Peers {
|
||||||
|
38
path/path.go
38
path/path.go
@ -26,8 +26,9 @@ type Latency struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Fullroute struct {
|
type Fullroute struct {
|
||||||
Next mtypes.NextHopTable `yaml:"NextHopTable"`
|
Next mtypes.NextHopTable `yaml:"NextHopTable"`
|
||||||
Dist mtypes.DistTable `yaml:"DistanceTable"`
|
Dist mtypes.DistTable `yaml:"DistanceTable"`
|
||||||
|
Dist_noAC mtypes.DistTable `yaml:"DistanceTableWithoutAdditionalaCost"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IG is a graph of integers that satisfies the Graph interface.
|
// IG is a graph of integers that satisfies the Graph interface.
|
||||||
@ -41,6 +42,7 @@ type IG struct {
|
|||||||
TimeoutCheckInterval time.Duration
|
TimeoutCheckInterval time.Duration
|
||||||
recalculateTime time.Time
|
recalculateTime time.Time
|
||||||
dlTable mtypes.DistTable
|
dlTable mtypes.DistTable
|
||||||
|
dlTable_noAC mtypes.DistTable
|
||||||
nhTable mtypes.NextHopTable
|
nhTable mtypes.NextHopTable
|
||||||
changed bool
|
changed bool
|
||||||
NhTableExpire time.Time
|
NhTableExpire time.Time
|
||||||
@ -133,7 +135,7 @@ func (g *IG) RecalculateNhTable(checkchange bool) (changed bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dist, next, _ := g.FloydWarshall(false)
|
dist, dist_noAC, next, _ := g.FloydWarshall(false)
|
||||||
changed = false
|
changed = false
|
||||||
if checkchange {
|
if checkchange {
|
||||||
CheckLoop:
|
CheckLoop:
|
||||||
@ -147,7 +149,7 @@ func (g *IG) RecalculateNhTable(checkchange bool) (changed bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.dlTable, g.nhTable = dist, next
|
g.dlTable, g.dlTable_noAC, g.nhTable = dist, dist_noAC, next
|
||||||
g.recalculateTime = time.Now()
|
g.recalculateTime = time.Now()
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -349,7 +351,7 @@ func (g *IG) RemoveAllNegativeValue() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextHopTable, err error) {
|
func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, dist_noAC mtypes.DistTable, next mtypes.NextHopTable, err error) {
|
||||||
if g.loglevel.LogInternal {
|
if g.loglevel.LogInternal {
|
||||||
if !again {
|
if !again {
|
||||||
fmt.Println("Internal: Start Floyd Warshall algorithm")
|
fmt.Println("Internal: Start Floyd Warshall algorithm")
|
||||||
@ -360,20 +362,25 @@ func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextH
|
|||||||
}
|
}
|
||||||
vert := g.Vertices()
|
vert := g.Vertices()
|
||||||
dist = make(mtypes.DistTable)
|
dist = make(mtypes.DistTable)
|
||||||
|
dist_noAC = make(mtypes.DistTable)
|
||||||
next = make(mtypes.NextHopTable)
|
next = make(mtypes.NextHopTable)
|
||||||
for u := range vert {
|
for u := range vert {
|
||||||
dist[u] = make(map[mtypes.Vertex]float64)
|
dist[u] = make(map[mtypes.Vertex]float64)
|
||||||
|
dist_noAC[u] = make(map[mtypes.Vertex]float64)
|
||||||
next[u] = make(map[mtypes.Vertex]mtypes.Vertex)
|
next[u] = make(map[mtypes.Vertex]mtypes.Vertex)
|
||||||
for v := range vert {
|
for v := range vert {
|
||||||
dist[u][v] = mtypes.Infinity
|
dist[u][v] = mtypes.Infinity
|
||||||
|
dist_noAC[u][v] = mtypes.Infinity
|
||||||
}
|
}
|
||||||
dist[u][u] = 0
|
dist[u][u] = 0
|
||||||
|
dist_noAC[u][u] = 0
|
||||||
for _, v := range g.Neighbors(u) {
|
for _, v := range g.Neighbors(u) {
|
||||||
w := g.Weight(u, v, true)
|
w := g.Weight(u, v, true)
|
||||||
wo := g.Weight(u, v, false)
|
wo := g.Weight(u, v, false)
|
||||||
if w < mtypes.Infinity {
|
if w < mtypes.Infinity {
|
||||||
v := v
|
v := v
|
||||||
dist[u][v] = w
|
dist[u][v] = w
|
||||||
|
dist_noAC[u][v] = wo
|
||||||
next[u][v] = v
|
next[u][v] = v
|
||||||
}
|
}
|
||||||
g.SetOldWeight(u, v, wo)
|
g.SetOldWeight(u, v, wo)
|
||||||
@ -385,6 +392,7 @@ func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextH
|
|||||||
if dist[i][k] < mtypes.Infinity && dist[k][j] < mtypes.Infinity {
|
if dist[i][k] < mtypes.Infinity && dist[k][j] < mtypes.Infinity {
|
||||||
if dist[i][j] > dist[i][k]+dist[k][j] {
|
if dist[i][j] > dist[i][k]+dist[k][j] {
|
||||||
dist[i][j] = dist[i][k] + dist[k][j]
|
dist[i][j] = dist[i][k] + dist[k][j]
|
||||||
|
dist_noAC[i][j] = dist_noAC[i][k] + dist_noAC[k][j]
|
||||||
next[i][j] = next[i][k]
|
next[i][j] = next[i][k]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,10 +407,11 @@ func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextH
|
|||||||
}
|
}
|
||||||
g.RemoveAllNegativeValue()
|
g.RemoveAllNegativeValue()
|
||||||
err = errors.New("negative cycle detected")
|
err = errors.New("negative cycle detected")
|
||||||
dist, next, _ = g.FloydWarshall(true)
|
dist, dist_noAC, next, _ = g.FloydWarshall(true)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
dist = make(mtypes.DistTable)
|
dist = make(mtypes.DistTable)
|
||||||
|
dist_noAC = make(mtypes.DistTable)
|
||||||
next = make(mtypes.NextHopTable)
|
next = make(mtypes.NextHopTable)
|
||||||
err = errors.New("negative cycle detected again")
|
err = errors.New("negative cycle detected again")
|
||||||
if g.loglevel.LogInternal {
|
if g.loglevel.LogInternal {
|
||||||
@ -452,8 +461,13 @@ func (g *IG) GetNHTable(recalculate bool) mtypes.NextHopTable {
|
|||||||
return g.nhTable
|
return g.nhTable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *IG) GetDtst() mtypes.DistTable {
|
func (g *IG) GetDtst(withAC bool) mtypes.DistTable {
|
||||||
return g.dlTable
|
if withAC {
|
||||||
|
return g.dlTable
|
||||||
|
} else {
|
||||||
|
return g.dlTable_noAC
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *IG) GetEdges(isOld bool, withAC bool) (edges map[mtypes.Vertex]map[mtypes.Vertex]float64) {
|
func (g *IG) GetEdges(isOld bool, withAC bool) (edges map[mtypes.Vertex]map[mtypes.Vertex]float64) {
|
||||||
@ -560,14 +574,16 @@ func Solve(filePath string, pe bool) error {
|
|||||||
input := string(inputb)
|
input := string(inputb)
|
||||||
all_edge, _ := ParseDistanceMatrix(input)
|
all_edge, _ := ParseDistanceMatrix(input)
|
||||||
g.UpdateLatencyMulti(all_edge, false, false)
|
g.UpdateLatencyMulti(all_edge, false, false)
|
||||||
dist, next, err := g.FloydWarshall(false)
|
dist, dist_noAC, next, err := g.FloydWarshall(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
}
|
}
|
||||||
|
g.dlTable, g.dlTable_noAC, g.nhTable = dist, dist_noAC, next
|
||||||
|
|
||||||
rr, _ := yaml.Marshal(Fullroute{
|
rr, _ := yaml.Marshal(Fullroute{
|
||||||
Dist: dist,
|
Dist: dist,
|
||||||
Next: next,
|
Dist_noAC: dist_noAC,
|
||||||
|
Next: next,
|
||||||
})
|
})
|
||||||
fmt.Print(string(rr))
|
fmt.Print(string(rr))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user