Skip to content

Commit

Permalink
Merge faf4c66 into 4b6d8ce
Browse files Browse the repository at this point in the history
  • Loading branch information
nandakishorepeddi committed May 29, 2024
2 parents 4b6d8ce + faf4c66 commit 80d6f68
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions pkg/networkmanager/networkmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
networkManagerPrefix = "[NetworkManager]"
timeoutSmall = 2 * time.Second
timeoutLarge = 180 * time.Second
DefaultL3Network = "Default L3-Network"
DefaultL3Network = "Default"
Ok = "Ok"
)

Expand Down Expand Up @@ -451,16 +451,26 @@ func GetTaskURIAndObjectIdFromResponse(response map[string]interface{}) (string,
}

func (nm *NetworkManager) NetworkRequestHandler(store interface{}) {
log.Debugf("%v PNK NetworkRequestHandler store %v ", networkManagerPrefix, store)
switch store.(type) {
case RouteStore:
routeStore := store.(RouteStore)
// Create the new l3 forwards
for bigip, rMap := range routeStore {
nm.L3ForwardStore.RLock()
log.Debugf("%v PNK NetworkRequestHandler rMap %v ", networkManagerPrefix, rMap)
log.Debugf("%v PNK NetworkRequestHandler bigip %v ", networkManagerPrefix, bigip)
log.Debugf("%v PNK NetworkRequestHandler nm.L3ForwardStore %v ", networkManagerPrefix, nm.L3ForwardStore)
log.Debugf("%v PNK NetworkRequestHandler nm.L3ForwardStore.InstanceStaticRoutes %v ", networkManagerPrefix, nm.L3ForwardStore.InstanceStaticRoutes)
log.Debugf("%v PNK NetworkRequestHandler nm.L3ForwardStore.CachedInstanceStaticRoutes %v ", networkManagerPrefix, nm.L3ForwardStore.CachedInstanceStaticRoutes)
log.Debugf("%v PNK NetworkRequestHandler nm.L3ForwardStore.InstanceStaticRoutes[bigip.InstanceId] %v ", networkManagerPrefix, nm.L3ForwardStore.InstanceStaticRoutes[bigip.InstanceId])
log.Debugf("%v PNK NetworkRequestHandler bigip.InstanceId %v ", networkManagerPrefix, bigip.InstanceId)
if cachedIsr, ok := nm.L3ForwardStore.InstanceStaticRoutes[bigip.InstanceId]; ok {
// enqueue the deleted routes
for config, l3Forward := range cachedIsr {
if _, ok := rMap[config]; !ok {
log.Debugf("%v PNK Delete NetworkRequestHandler config %v ", networkManagerPrefix, config)
log.Debugf("%v PNK Delete Action NetworkRequestHandler ", networkManagerPrefix)
nm.NetworkChan <- &NetworkConfigRequest{
NetworkConfig: l3Forward,
BigIp: bigip,
Expand All @@ -471,6 +481,8 @@ func (nm *NetworkManager) NetworkRequestHandler(store interface{}) {
// enqueue the created routes
for config, l3Forward := range rMap {
if _, ok := cachedIsr[config]; !ok {
log.Debugf("%v PNK Create NetworkRequestHandler config %v ", networkManagerPrefix, config)
log.Debugf("%v PNK Create Action NetworkRequestHandler ", networkManagerPrefix)
nm.NetworkChan <- &NetworkConfigRequest{
NetworkConfig: l3Forward,
BigIp: bigip,
Expand Down Expand Up @@ -510,6 +522,8 @@ func (nm *NetworkManager) HandleL3ForwardRequest(req *NetworkConfigRequest, l3Fo
bigipStatus := cisapiv1.BigIPStatus{
BigIPAddress: req.BigIp.IPaddress,
}
log.Debugf("%v PNK HandleL3ForwardRequest req.Action %v ", networkManagerPrefix, req.Action)
log.Debugf("%v PNK HandleL3ForwardRequest req %v ", networkManagerPrefix, req)
switch req.Action {
case Create:
// check if the l3 forward already exists
Expand Down Expand Up @@ -547,9 +561,9 @@ func (nm *NetworkManager) HandleL3ForwardRequest(req *NetworkConfigRequest, l3Fo
nm.CMTokenManager.StatusManager.AddRequest(statusmanager.DeployConfig, "", "", false, &bigipStatus)
nm.L3ForwardStore.addL3ForwardEntry(req.BigIp.InstanceId, *l3Forward)
// once event is processed remove entry from cache
nm.L3ForwardStore.removeL3ForwardEntryFromCache(req.BigIp.InstanceId, *l3Forward)
// nm.L3ForwardStore.removeL3ForwardEntryFromCache(req.BigIp.InstanceId, *l3Forward)
case Delete:
log.Warningf("delete event")
log.Warningf("%v delete event", networkManagerPrefix)
// check if the l3 forward already exists
if !nm.L3ForwardStore.getL3ForwardEntry(req.BigIp.InstanceId, *l3Forward) {
log.Debugf("%v l3 forward does not exist hence skipping the deletion: %v", networkManagerPrefix, l3Forward)
Expand All @@ -576,6 +590,8 @@ func (nm *NetworkManager) HandleL3ForwardRequest(req *NetworkConfigRequest, l3Fo
nm.CMTokenManager.StatusManager.AddRequest(statusmanager.DeployConfig, "", "", false, &bigipStatus)
log.Debugf("%v successfully deleted l3 forward %v", networkManagerPrefix, l3Forward)
nm.L3ForwardStore.deleteL3ForwardEntry(req.BigIp.InstanceId, l3Forward.Config)
// once event is processed remove entry from cache
nm.L3ForwardStore.removeL3ForwardEntryFromCache(req.BigIp.InstanceId, *l3Forward)
}
}

Expand All @@ -585,6 +601,9 @@ func (fs *L3ForwardStore) deleteL3ForwardEntry(instanceId string, config StaticR
if isr, ok := fs.InstanceStaticRoutes[instanceId]; ok {
delete(isr, config)
}
log.Debugf("%v PNK deleteL3ForwardEntry fs.CachedInstanceStaticRoutes %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes)
log.Debugf("%v PNK deleteL3ForwardEntry config %v", networkManagerPrefix, config)
log.Debugf("%v PNK deleteL3ForwardEntry instanceId %v", networkManagerPrefix, instanceId)
}

func (fs *L3ForwardStore) getL3ForwardEntry(instanceId string, l3Forward L3Forward) bool {
Expand All @@ -595,6 +614,9 @@ func (fs *L3ForwardStore) getL3ForwardEntry(instanceId string, l3Forward L3Forwa
return ok
}
}
log.Debugf("%v PNK getL3ForwardEntry fs.CachedInstanceStaticRoutes %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes)
log.Debugf("%v PNK getL3ForwardEntry l3Forward.Config %v", networkManagerPrefix, l3Forward.Config)
log.Debugf("%v PNK getL3ForwardEntry instanceId %v", networkManagerPrefix, instanceId)
return false
}

Expand All @@ -608,6 +630,10 @@ func (fs *L3ForwardStore) checkL3ForwardEntryInCache(bigIpInstanceId string, ret
if _, ok := fs.CachedInstanceStaticRoutes[bigIpInstanceId]; !ok {
fs.CachedInstanceStaticRoutes[bigIpInstanceId] = map[StaticRouteConfig]struct{}{}
}
log.Debugf("%v PNK checkL3ForwardEntryInCache fs.CachedInstanceStaticRoutes[bigIpInstanceId] %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes[bigIpInstanceId])
log.Debugf("%v PNK checkL3ForwardEntryInCache fs.CachedInstanceStaticRoutes %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes)
log.Debugf("%v PNK checkL3ForwardEntryInCache l3Forward.Config %v", networkManagerPrefix, l3Forward.Config)
log.Debugf("%v PNK checkL3ForwardEntryInCache bigIpInstanceId %v", networkManagerPrefix, bigIpInstanceId)
if _, ok := fs.CachedInstanceStaticRoutes[bigIpInstanceId][l3Forward.Config]; !ok {
fs.CachedInstanceStaticRoutes[bigIpInstanceId][l3Forward.Config] = struct{}{}
return false
Expand All @@ -623,17 +649,44 @@ func (fs *L3ForwardStore) removeL3ForwardEntryFromCache(bigIpInstanceId string,
delete(fs.CachedInstanceStaticRoutes[bigIpInstanceId], l3Forward.Config)
}
}
log.Debugf("%v PNK removeL3ForwardEntryFromCache fs.CachedInstanceStaticRoutes %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes)
log.Debugf("%v PNK removeL3ForwardEntryFromCache l3Forward.Config %v", networkManagerPrefix, l3Forward.Config)
log.Debugf("%v PNK removeL3ForwardEntryFromCache bigIpInstanceId %v", networkManagerPrefix, bigIpInstanceId)
}

func (fs *L3ForwardStore) addL3ForwardEntryFromCache(bigIpInstanceId string, l3Forward L3Forward) {
fs.Lock()
defer fs.Unlock()
if _, ok := fs.CachedInstanceStaticRoutes[bigIpInstanceId]; ok {
if _, ok := fs.CachedInstanceStaticRoutes[bigIpInstanceId][l3Forward.Config]; !ok {
fs.CachedInstanceStaticRoutes[bigIpInstanceId][l3Forward.Config] = struct{}{}
}
}
log.Debugf("%v PNK addL3ForwardEntryFromCache fs.CachedInstanceStaticRoutes %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes)
log.Debugf("%v PNK addL3ForwardEntryFromCache l3Forward.Config %v", networkManagerPrefix, l3Forward.Config)
log.Debugf("%v PNK addL3ForwardEntryFromCache bigIpInstanceId %v", networkManagerPrefix, bigIpInstanceId)
}

func (fs *L3ForwardStore) addL3ForwardEntry(instanceId string, l3Forward L3Forward) {
log.Debugf("%v PNK before addL3ForwardEntry fs.CachedInstanceStaticRoutes %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes)
log.Debugf("%v PNK before addL3ForwardEntry l3Forward.Config %v", networkManagerPrefix, l3Forward.Config)
log.Debugf("%v PNK before addL3ForwardEntry instanceId %v", networkManagerPrefix, instanceId)
fs.Lock()
defer fs.Unlock()
if isr, ok := fs.InstanceStaticRoutes[instanceId]; ok {
isr[l3Forward.Config] = l3Forward
}
log.Debugf("%v PNK after addL3ForwardEntry fs.CachedInstanceStaticRoutes %v", networkManagerPrefix, fs.CachedInstanceStaticRoutes)
log.Debugf("%v PNK after addL3ForwardEntry l3Forward.Config %v", networkManagerPrefix, l3Forward.Config)
log.Debugf("%v PNK after addL3ForwardEntry instanceId %v", networkManagerPrefix, instanceId)
log.Debugf("%v PNK after addL3ForwardEntry isr[l3Forward.Config] %v", networkManagerPrefix, l3Forward)
}

func getRetryTimeout(retryTimeout int) int {
// Reset to 0 after 64 seconds
if retryTimeout >= 64 {
retryTimeout = 0
}
if retryTimeout == 0 {
retryTimeout = 1
} else {
Expand Down

0 comments on commit 80d6f68

Please sign in to comment.