Skip to content

Commit 421cab7

Browse files
author
Vipin Jain
committed
free up resources upon network/ep delete
1 parent 7d8f10d commit 421cab7

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

drivers/ovsdriver.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,15 @@ func (d *OvsDriver) DeleteNetwork(value string) error {
562562
}
563563
}
564564

565+
if cfgNetState.SubnetIp == "auto" {
566+
log.Printf("freeing subnet %s/%d \n",
567+
operNwState.SubnetIp, operNwState.SubnetLen)
568+
err = gOper.FreeSubnet(operNwState.SubnetIp)
569+
if err != nil {
570+
log.Printf("error '%s' freeing the subnet \n", err)
571+
}
572+
}
573+
565574
err = gOper.Update(d.stateDriver)
566575
if err != nil {
567576
log.Printf("error updating the global state - %s \n", err)
@@ -713,7 +722,6 @@ func (d *OvsDriver) CreateEndpoint(id string) error {
713722
log.Printf("error acquiring subnet ip '%s' \n", err)
714723
return err
715724
}
716-
operNwState.IpAllocMap.Set(ipAddrBit)
717725
log.Printf("Ep %s was allocated ip address %s \n", id, ipAddress)
718726
} else if ipAddress != "" && operNwState.SubnetIp != "" {
719727
ipAddrBit, err = netutils.GetIpNumber(
@@ -723,8 +731,8 @@ func (d *OvsDriver) CreateEndpoint(id string) error {
723731
ipAddress, operNwState.SubnetIp, operNwState.SubnetLen, err)
724732
return err
725733
}
726-
operNwState.IpAllocMap.Set(ipAddrBit)
727734
}
735+
operNwState.IpAllocMap.Set(ipAddrBit)
728736

729737
// deprecate - bitset.WordCount gives the following value
730738
operNwState.EpCount += 1
@@ -740,7 +748,6 @@ func (d *OvsDriver) CreateEndpoint(id string) error {
740748
}
741749
}()
742750

743-
//all went well, update the runtime state of network and endpoint
744751
operEpState := OvsOperEndpointState{
745752
StateDriver: d.stateDriver,
746753
Id: id,
@@ -791,7 +798,6 @@ func (d *OvsDriver) DeleteEndpoint(value string) (err error) {
791798
epOper.Clear()
792799
}()
793800

794-
// delete the internal ovs port corresponding to the endpoint
795801
portName, err := d.getPortOrIntfNameFromId(epCfg.Id, GET_PORT_NAME)
796802
if err != nil {
797803
return err
@@ -814,6 +820,15 @@ func (d *OvsDriver) DeleteEndpoint(value string) (err error) {
814820
return err
815821
}
816822

823+
ipAddrBit, err := netutils.GetIpNumber(
824+
operNwState.SubnetIp, operNwState.SubnetLen, 32, epOper.IpAddress)
825+
if err != nil {
826+
log.Printf("error getting host id from %s subnet %s/%d err '%s'\n",
827+
epOper.IpAddress, operNwState.SubnetIp, operNwState.SubnetLen, err)
828+
} else {
829+
operNwState.IpAllocMap.Clear(ipAddrBit)
830+
}
831+
817832
operNwState.EpCount -= 1
818833
err = operNwState.Write()
819834
if err != nil {

drivers/ovsdriver_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const (
3636
testPktTag = 100
3737
testExtPktTag = 10000
3838
testIntfName = "testIntf"
39+
testSubnetIp = "10.1.1.0"
40+
testSubnetLen = 24
41+
testEpAddress = "10.1.1.1"
3942

4043
READ_EP int = iota
4144
READ_EP_WITH_INTF
@@ -82,6 +85,8 @@ func (d *testOvsStateDriver) readStateHelper(isCreateEp bool, oper int,
8285
operNw.Id = testOvsNwId
8386
operNw.PktTag = testPktTag
8487
operNw.ExtPktTag = testExtPktTag
88+
operNw.SubnetIp = testSubnetIp
89+
operNw.SubnetLen = testSubnetLen
8590
return nil
8691
}
8792

@@ -128,10 +133,13 @@ func (d *testOvsStateDriver) readStateHelper(isCreateEp bool, oper int,
128133
operEp.Id = deleteVxlanEpId
129134
operEp.NetId = testOvsNwId
130135
operEp.VtepIp = vxlanPeerIp
136+
operEp.IpAddress = testEpAddress
131137
} else if oper == READ_EP_WITH_INTF {
132138
operEp.Id = deleteEpWithIntfId
139+
operEp.IpAddress = testEpAddress
133140
} else {
134141
operEp.Id = deleteEpId
142+
operEp.IpAddress = testEpAddress
135143
}
136144
}
137145
operEp.NetId = testOvsNwId

gstate/gstate.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,15 @@ func (g *Oper) AllocSubnet() (string, error) {
357357
}
358358

359359
func (g *Oper) FreeSubnet(subnetIp string) error {
360+
subnetId, err := netutils.GetIpNumber(g.SubnetPool, g.SubnetLen,
361+
g.AllocSubnetLen, subnetIp)
362+
if err != nil {
363+
log.Printf("error '%s' getting subnetid for subnet %s/%d \n",
364+
err, subnetIp, g.SubnetLen)
365+
}
366+
g.FreeSubnets.Set(subnetId)
360367

361-
return nil
368+
return err
362369
}
363370

364371
func (gc *Cfg) Process() (*Oper, error) {

0 commit comments

Comments
 (0)