Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: NAT Interface and AddressPool API changes #1595

Merged
merged 9 commits into from
Jan 7, 2020
8 changes: 8 additions & 0 deletions clientv2/linux/data_change_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ type PutDSL interface {
NAT44Global(nat *nat.Nat44Global) PutDSL
// DNAT44 adds a request to create or update DNAT44 configuration
DNAT44(dnat *nat.DNat44) PutDSL
// NAT44Interface adds a request to create or update NAT44 interface configuration.
NAT44Interface(natIf *nat.Nat44Interface) PutDSL
// NAT44AddressPool adds a request to create or update NAT44 address pool.
NAT44AddressPool(pool *nat.Nat44AddressPool) PutDSL
// IPSecSA adds request to create a new Security Association
IPSecSA(sa *ipsec.SecurityAssociation) PutDSL
// IPSecSPD adds request to create a new Security Policy Database
Expand Down Expand Up @@ -186,6 +190,10 @@ type DeleteDSL interface {
NAT44Global() DeleteDSL
// DNAT44 adds a request to delete an existing DNAT-44 configuration
DNAT44(label string) DeleteDSL
// NAT44Interface adds a request to delete NAT44 interface configuration.
NAT44Interface(natIf *nat.Nat44Interface) DeleteDSL
// NAT44AddressPool adds a request to delete NAT44 address pool.
NAT44AddressPool(pool *nat.Nat44AddressPool) DeleteDSL
// IPSecSA adds request to delete a Security Association
IPSecSA(saIndex string) DeleteDSL
// IPSecSPD adds request to delete a Security Policy Database
Expand Down
4 changes: 4 additions & 0 deletions clientv2/linux/data_resync_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ type DataResyncDSL interface {
NAT44Global(nat *nat.Nat44Global) DataResyncDSL
// DNAT44 adds DNAT44 configuration to the RESYNC request
DNAT44(dnat *nat.DNat44) DataResyncDSL
// NAT44Interface adds NAT44 interface configuration to the RESYNC request.
NAT44Interface(natIf *nat.Nat44Interface) DataResyncDSL
// NAT44AddressPool adds NAT44 address pool configuration to the RESYNC request.
NAT44AddressPool(pool *nat.Nat44AddressPool) DataResyncDSL
// IPSecSA adds request to RESYNC a new Security Association
IPSecSA(sa *ipsec.SecurityAssociation) DataResyncDSL
// IPSecSPD adds request to RESYNC a new Security Policy Database
Expand Down
24 changes: 24 additions & 0 deletions clientv2/linux/dbadapter/data_change_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ func (dsl *PutDSL) DNAT44(nat44 *nat.DNat44) linuxclient.PutDSL {
return dsl
}

// NAT44Interface adds a request to create or update NAT44 interface configuration.
func (dsl *PutDSL) NAT44Interface(natIf *nat.Nat44Interface) linuxclient.PutDSL {
dsl.parent.txn.Put(models.Key(natIf), natIf)
return dsl
}

// NAT44AddressPool adds a request to create or update NAT44 address pool.
func (dsl *PutDSL) NAT44AddressPool(pool *nat.Nat44AddressPool) linuxclient.PutDSL {
dsl.parent.txn.Put(models.Key(pool), pool)
return dsl
}

// IPSecSA adds request to create a new Security Association
func (dsl *PutDSL) IPSecSA(sa *ipsec.SecurityAssociation) linuxclient.PutDSL {
dsl.vppPut.IPSecSA(sa)
Expand Down Expand Up @@ -416,6 +428,18 @@ func (dsl *DeleteDSL) DNAT44(label string) linuxclient.DeleteDSL {
return dsl
}

// NAT44Interface adds a request to delete NAT44 interface configuration.
func (dsl *DeleteDSL) NAT44Interface(natIf *nat.Nat44Interface) linuxclient.DeleteDSL {
dsl.parent.txn.Delete(models.Key(natIf))
return dsl
}

// NAT44AddressPool adds a request to create or update NAT44 address pool.
func (dsl *DeleteDSL) NAT44AddressPool(pool *nat.Nat44AddressPool) linuxclient.DeleteDSL {
dsl.parent.txn.Delete(models.Key(pool))
return dsl
}

// IPSecSA adds request to delete a Security Association
func (dsl *DeleteDSL) IPSecSA(saIndex string) linuxclient.DeleteDSL {
dsl.vppDelete.IPSecSA(saIndex)
Expand Down
18 changes: 18 additions & 0 deletions clientv2/linux/dbadapter/data_resync_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ func (dsl *DataResyncDSL) DNAT44(nat44 *nat.DNat44) linuxclient.DataResyncDSL {
return dsl
}

// NAT44Interface adds NAT44 interface configuration to the RESYNC request.
func (dsl *DataResyncDSL) NAT44Interface(natIf *nat.Nat44Interface) linuxclient.DataResyncDSL {
key := models.Key(natIf)
dsl.txn.Put(key, natIf)
dsl.txnKeys = append(dsl.txnKeys, key)

return dsl
}

// NAT44AddressPool adds NAT44 address pool configuration to the RESYNC request.
func (dsl *DataResyncDSL) NAT44AddressPool(pool *nat.Nat44AddressPool) linuxclient.DataResyncDSL {
key := models.Key(pool)
dsl.txn.Put(key, pool)
dsl.txnKeys = append(dsl.txnKeys, key)

return dsl
}

// IPSecSA adds request to RESYNC a new Security Association
func (dsl *DataResyncDSL) IPSecSA(sa *ipsec.SecurityAssociation) linuxclient.DataResyncDSL {
dsl.vppDataResync.IPSecSA(sa)
Expand Down
8 changes: 8 additions & 0 deletions clientv2/vpp/data_change_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ type PutDSL interface {
NAT44Global(nat *nat.Nat44Global) PutDSL
// DNAT44 adds a request to create or update DNAT44 configuration
DNAT44(dnat *nat.DNat44) PutDSL
// NAT44Interface adds a request to create or update NAT44 interface configuration.
NAT44Interface(natIf *nat.Nat44Interface) PutDSL
// NAT44AddressPool adds a request to create or update NAT44 address pool.
NAT44AddressPool(pool *nat.Nat44AddressPool) PutDSL
// IPSecSA adds request to create a new Security Association
IPSecSA(sa *ipsec.SecurityAssociation) PutDSL
// IPSecSPD adds request to create a new Security Policy Database
Expand Down Expand Up @@ -136,6 +140,10 @@ type DeleteDSL interface {
NAT44Global() DeleteDSL
// DNAT44 adds a request to delete an existing DNAT44 configuration
DNAT44(label string) DeleteDSL
// NAT44Interface adds a request to delete NAT44 interface configuration.
NAT44Interface(natIf *nat.Nat44Interface) DeleteDSL
// NAT44AddressPool adds a request to delete NAT44 address pool.
NAT44AddressPool(pool *nat.Nat44AddressPool) DeleteDSL
// IPSecSA adds request to delete a Security Association
IPSecSA(saIndex string) DeleteDSL
// IPSecSPD adds request to delete a Security Policy Database
Expand Down
4 changes: 4 additions & 0 deletions clientv2/vpp/data_resync_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type DataResyncDSL interface {
NAT44Global(nat *nat.Nat44Global) DataResyncDSL
// DNAT44 adds DNAT44 configuration to the RESYNC request
DNAT44(dnat *nat.DNat44) DataResyncDSL
// NAT44Interface adds NAT44 interface configuration to the RESYNC request.
NAT44Interface(natIf *nat.Nat44Interface) DataResyncDSL
// NAT44AddressPool adds NAT44 address pool configuration to the RESYNC request.
NAT44AddressPool(pool *nat.Nat44AddressPool) DataResyncDSL
// IPSecSA adds request to RESYNC a new Security Association
IPSecSA(sa *ipsec.SecurityAssociation) DataResyncDSL
// IPSecSPD adds request to RESYNC a new Security Policy Database
Expand Down
24 changes: 24 additions & 0 deletions clientv2/vpp/dbadapter/data_change_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ func (dsl *PutDSL) DNAT44(nat44 *nat.DNat44) vppclient.PutDSL {
return dsl
}

// NAT44Interface adds a request to create or update NAT44 interface configuration.
func (dsl *PutDSL) NAT44Interface(natIf *nat.Nat44Interface) vppclient.PutDSL {
dsl.parent.txn.Put(models.Key(natIf), natIf)
return dsl
}

// NAT44AddressPool adds a request to create or update NAT44 address pool.
func (dsl *PutDSL) NAT44AddressPool(pool *nat.Nat44AddressPool) vppclient.PutDSL {
dsl.parent.txn.Put(models.Key(pool), pool)
return dsl
}

// IPSecSA adds request to create a new Security Association
func (dsl *PutDSL) IPSecSA(sa *ipsec.SecurityAssociation) vppclient.PutDSL {
dsl.parent.txn.Put(ipsec.SAKey(sa.Index), sa)
Expand Down Expand Up @@ -299,6 +311,18 @@ func (dsl *DeleteDSL) DNAT44(label string) vppclient.DeleteDSL {
return dsl
}

// NAT44Interface adds a request to delete NAT44 interface configuration.
func (dsl *DeleteDSL) NAT44Interface(natIf *nat.Nat44Interface) vppclient.DeleteDSL {
dsl.parent.txn.Delete(models.Key(natIf))
return dsl
}

// NAT44AddressPool adds a request to create or update NAT44 address pool.
func (dsl *DeleteDSL) NAT44AddressPool(pool *nat.Nat44AddressPool) vppclient.DeleteDSL {
dsl.parent.txn.Delete(models.Key(pool))
return dsl
}

// IPSecSA adds request to create a new Security Association
func (dsl *DeleteDSL) IPSecSA(saIndex string) vppclient.DeleteDSL {
dsl.parent.txn.Delete(ipsec.SAKey(saIndex))
Expand Down
18 changes: 18 additions & 0 deletions clientv2/vpp/dbadapter/data_resync_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@ func (dsl *DataResyncDSL) DNAT44(nat44 *nat.DNat44) vppclient.DataResyncDSL {
return dsl
}

// NAT44Interface adds NAT44 interface configuration to the RESYNC request.
func (dsl *DataResyncDSL) NAT44Interface(natIf *nat.Nat44Interface) vppclient.DataResyncDSL {
key := models.Key(natIf)
dsl.txn.Put(key, natIf)
dsl.txnKeys = append(dsl.txnKeys, key)

return dsl
}

// NAT44AddressPool adds NAT44 address pool configuration to the RESYNC request.
func (dsl *DataResyncDSL) NAT44AddressPool(pool *nat.Nat44AddressPool) vppclient.DataResyncDSL {
key := models.Key(pool)
dsl.txn.Put(key, pool)
dsl.txnKeys = append(dsl.txnKeys, key)

return dsl
}

// IPSecSA adds request to create a new Security Association
func (dsl *DataResyncDSL) IPSecSA(sa *ipsec.SecurityAssociation) vppclient.DataResyncDSL {
key := ipsec.SAKey(sa.Index)
Expand Down
79 changes: 39 additions & 40 deletions examples/kvscheduler/nat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ func testLocalClientWithScheduler() {
VppInterface(server1VPPTap).
VppInterface(server2VPPTap).
NAT44Global(natGlobal).
NAT44Interface(natInterfaceTapHost).
NAT44Interface(natInterfaceTapClient).
NAT44Interface(natInterfaceTapServer1).
NAT44Interface(natInterfaceTapServer2).
NAT44AddressPool(natPool1).
NAT44AddressPool(natPool2).
DNAT44(tcpServiceDNAT).
DNAT44(udpServiceDNAT).
DNAT44(idDNAT).
Expand Down Expand Up @@ -257,7 +263,7 @@ const (
emptyDNATLabel = "empty-dnat"

natPoolAddr1 = hostNetPrefix + "100"
natPoolAddr2 = hostNetPrefix + "200"
natPoolAddr2 = hostNetPrefix + "101"
natPoolAddr3 = hostNetPrefix + "250"
)

Expand Down Expand Up @@ -460,45 +466,38 @@ var (
MaxFragments: 10,
DropFragments: true,
},
NatInterfaces: []*vpp_nat.Nat44Global_Interface{
{
Name: vppTapHostLogicalName,
IsInside: false,
OutputFeature: true,
},
{
Name: vppTapClientLogicalName,
IsInside: false,
OutputFeature: false,
},
{
Name: vppTapClientLogicalName,
IsInside: true, // just to test in & out together
OutputFeature: false,
},
{
Name: vppTapServer1LogicalName,
IsInside: true,
OutputFeature: false,
},
{
Name: vppTapServer2LogicalName,
IsInside: true,
OutputFeature: false,
},
},
AddressPool: []*vpp_nat.Nat44Global_Address{
{
Address: natPoolAddr1,
},
{
Address: natPoolAddr2,
},
{
Address: natPoolAddr3,
TwiceNat: true,
},
},
}

/* NAT interfaces */

natInterfaceTapHost = &vpp_nat.Nat44Interface{
Name: vppTapHostLogicalName,
NatOutside: true,
OutputFeature: true,
}
natInterfaceTapClient = &vpp_nat.Nat44Interface{
Name: vppTapClientLogicalName,
NatInside: true, // just to test in & out together
NatOutside: true,
}
natInterfaceTapServer1 = &vpp_nat.Nat44Interface{
Name: vppTapServer1LogicalName,
NatInside: true,
}
natInterfaceTapServer2 = &vpp_nat.Nat44Interface{
Name: vppTapServer2LogicalName,
NatInside: true,
}

/* NAT pools */

natPool1 = &vpp_nat.Nat44AddressPool{
FirstIp: natPoolAddr1,
LastIp: natPoolAddr2,
}
natPool2 = &vpp_nat.Nat44AddressPool{
FirstIp: natPoolAddr3,
TwiceNat: true,
}

/* TCP service */
Expand Down
Loading