mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
88 lines
2.4 KiB
Go
88 lines
2.4 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package routes
|
|
|
|
import (
|
|
"github.com/hanzozt/zt/v2/controller/env"
|
|
"github.com/hanzozt/zt/v2/controller/model"
|
|
"github.com/hanzozt/zt/v2/controller/response"
|
|
"github.com/hanzozt/zt/v2/controller/rest_model"
|
|
)
|
|
|
|
const EntityNameLink = "links"
|
|
|
|
var LinkLinkFactory = NewLinkLinkFactory()
|
|
|
|
type LinkLinkFactoryIml struct {
|
|
BasicFabricLinkFactory
|
|
}
|
|
|
|
func NewLinkLinkFactory() *LinkLinkFactoryIml {
|
|
return &LinkLinkFactoryIml{
|
|
BasicFabricLinkFactory: *NewBasicFabricLinkFactory(EntityNameLink),
|
|
}
|
|
}
|
|
|
|
func (factory *LinkLinkFactoryIml) Links(entity LinkEntity) rest_model.Links {
|
|
links := factory.BasicFabricLinkFactory.Links(entity)
|
|
return links
|
|
}
|
|
|
|
func MapLinkToRestModel(ae *env.AppEnv, _ *response.RequestContext, link *model.Link) (interface{}, error) {
|
|
n := ae.GetHostController().GetNetwork()
|
|
iteration := int64(link.Iteration)
|
|
staticCost := int64(link.StaticCost)
|
|
linkStateStr := link.CurrentState().Mode.String()
|
|
|
|
down := link.IsDown()
|
|
|
|
destRouter := link.GetDest()
|
|
if destRouter == nil {
|
|
var err error
|
|
destRouter, err = n.Router.Read(link.DstId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
ret := &rest_model.LinkDetail{
|
|
Cost: &link.Cost,
|
|
DestLatency: &link.DstLatency,
|
|
DestRouter: ToFabricEntityRef(destRouter.Name, destRouter, FabricRouterLinkFactory),
|
|
Down: &down,
|
|
ID: &link.Id,
|
|
SourceLatency: &link.SrcLatency,
|
|
SourceRouter: ToFabricEntityRef(link.Src.Name, link.Src, FabricRouterLinkFactory),
|
|
State: &linkStateStr,
|
|
StaticCost: &staticCost,
|
|
Protocol: &link.Protocol,
|
|
Iteration: &iteration,
|
|
}
|
|
|
|
if connState := link.GetConnsState(); connState != nil {
|
|
for _, c := range connState.Conns {
|
|
ret.Connections = append(ret.Connections, &rest_model.LinkConnection{
|
|
Dest: c.RemoteAddr,
|
|
Source: c.LocalAddr,
|
|
Type: c.Type,
|
|
})
|
|
}
|
|
}
|
|
|
|
return ret, nil
|
|
}
|