<commit_before>// Copyright (c) 2017 Cisco and/or its affiliates.
//
// 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:
//
//     http://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 defaultplugins

import (
	"strconv"
	"strings"

	"github.com/ligato/cn-infra/datasync"
	log "github.com/ligato/cn-infra/logging/logrus"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/aclplugin/model/acl"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/ifplugin/model/bfd"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/ifplugin/model/interfaces"
	intf "github.com/ligato/vpp-agent/plugins/defaultplugins/ifplugin/model/interfaces"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/l2plugin/model/l2"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/l3plugin/model/l3"
)

// DataResyncReq is used to transfer expected configuration of the VPP to the plugins
type DataResyncReq struct {
	// ACLs is a list af all access lists that are expected to be in VPP after RESYNC
	ACLs []*acl.AccessLists_Acl
	// Interfaces is a list af all interfaces that are expected to be in VPP after RESYNC
	Interfaces []*interfaces.Interfaces_Interface
	// SingleHopBFDSession is a list af all BFD sessions that are expected to be in VPP after RESYNC
	SingleHopBFDSession []*bfd.SingleHopBFD_Session
	// SingleHopBFDKey is a list af all BFD authentication keys that are expected to be in VPP after RESYNC
	SingleHopBFDKey []*bfd.SingleHopBFD_Key
	// SingleHopBFDEcho is a list af all BFD echo functions that are expected to be in VPP after RESYNC
	SingleHopBFDEcho []*bfd.SingleHopBFD_EchoFunction
	// BridgeDomains is a list af all BDs that are expected to be in VPP after RESYNC
	BridgeDomains []*l2.BridgeDomains_BridgeDomain
	// FibTableEntries is a list af all FIBs that are expected to be in VPP after RESYNC
	FibTableEntries []*l2.FibTableEntries_FibTableEntry
	// XConnects is a list af all XCons that are expected to be in VPP after RESYNC
	XConnects []*l2.XConnectPairs_XConnectPair
	// StaticRoutes is a list af all Static Routes that are expected to be in VPP after RESYNC
	StaticRoutes []*l3.StaticRoutes_Route
}

// NewDataResyncReq is a constructor
func NewDataResyncReq() *DataResyncReq {
	return &DataResyncReq{
		// ACLs is a list af all access lists that are expected to be in VPP after RESYNC
		ACLs: []*acl.AccessLists_Acl{},
		// Interfaces is a list af all interfaces that are expected to be in VPP after RESYNC
		Interfaces: []*interfaces.Interfaces_Interface{},
		// SingleHopBFDSession is a list af all BFD sessions that are expected to be in VPP after RESYNC
		SingleHopBFDSession: []*bfd.SingleHopBFD_Session{},
		// SingleHopBFDKey is a list af all BFD authentication keys that are expected to be in VPP after RESYNC
		SingleHopBFDKey: []*bfd.SingleHopBFD_Key{},
		// SingleHopBFDEcho is a list af all BFD echo functions that are expected to be in VPP after RESYNC
		SingleHopBFDEcho: []*bfd.SingleHopBFD_EchoFunction{},
		// BridgeDomains is a list af all BDs that are expected to be in VPP after RESYNC
		BridgeDomains: []*l2.BridgeDomains_BridgeDomain{},
		// FibTableEntries is a list af all FIBs that are expected to be in VPP after RESYNC
		FibTableEntries: []*l2.FibTableEntries_FibTableEntry{},
		// XConnects is a list af all XCons that are expected to be in VPP after RESYNC
		XConnects: []*l2.XConnectPairs_XConnectPair{},
		// StaticRoutes is a list af all Static Routes that are expected to be in VPP after RESYNC
		StaticRoutes: []*l3.StaticRoutes_Route{}}
}

// delegates resync request to ifplugin/l2plugin/l3plugin resync requests (in this particular order)
func (plugin *Plugin) resyncConfigPropageRequest(req *DataResyncReq) error {
	log.DefaultLogger().Info("resync the VPP Configuration begin")

	plugin.ifConfigurator.Resync(req.Interfaces)
	plugin.aclConfigurator.Resync(req.ACLs)
	plugin.bfdConfigurator.ResyncAuthKey(req.SingleHopBFDKey)
	plugin.bfdConfigurator.ResyncSession(req.SingleHopBFDSession)
	plugin.bfdConfigurator.ResyncEchoFunction(req.SingleHopBFDEcho)
	plugin.bdConfigurator.Resync(req.BridgeDomains)
	plugin.fibConfigurator.Resync(req.FibTableEntries)
	plugin.xcConfigurator.Resync(req.XConnects)
	plugin.routeConfigurator.Resync(req.StaticRoutes)

	log.DefaultLogger().Debug("resync the VPP Configuration end")<commit_msg>Measure vpp config resync<commit_after>// Copyright (c) 2017 Cisco and/or its affiliates.
//
// 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:
//
//     http://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 defaultplugins

import (
	"strconv"
	"strings"

	"github.com/ligato/cn-infra/datasync"
	log "github.com/ligato/cn-infra/logging/logrus"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/aclplugin/model/acl"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/ifplugin/model/bfd"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/ifplugin/model/interfaces"
	intf "github.com/ligato/vpp-agent/plugins/defaultplugins/ifplugin/model/interfaces"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/l2plugin/model/l2"
	"github.com/ligato/vpp-agent/plugins/defaultplugins/l3plugin/model/l3"
	"time"
)

// DataResyncReq is used to transfer expected configuration of the VPP to the plugins
type DataResyncReq struct {
	// ACLs is a list af all access lists that are expected to be in VPP after RESYNC
	ACLs []*acl.AccessLists_Acl
	// Interfaces is a list af all interfaces that are expected to be in VPP after RESYNC
	Interfaces []*interfaces.Interfaces_Interface
	// SingleHopBFDSession is a list af all BFD sessions that are expected to be in VPP after RESYNC
	SingleHopBFDSession []*bfd.SingleHopBFD_Session
	// SingleHopBFDKey is a list af all BFD authentication keys that are expected to be in VPP after RESYNC
	SingleHopBFDKey []*bfd.SingleHopBFD_Key
	// SingleHopBFDEcho is a list af all BFD echo functions that are expected to be in VPP after RESYNC
	SingleHopBFDEcho []*bfd.SingleHopBFD_EchoFunction
	// BridgeDomains is a list af all BDs that are expected to be in VPP after RESYNC
	BridgeDomains []*l2.BridgeDomains_BridgeDomain
	// FibTableEntries is a list af all FIBs that are expected to be in VPP after RESYNC
	FibTableEntries []*l2.FibTableEntries_FibTableEntry
	// XConnects is a list af all XCons that are expected to be in VPP after RESYNC
	XConnects []*l2.XConnectPairs_XConnectPair
	// StaticRoutes is a list af all Static Routes that are expected to be in VPP after RESYNC
	StaticRoutes []*l3.StaticRoutes_Route
}

// NewDataResyncReq is a constructor
func NewDataResyncReq() *DataResyncReq {
	return &DataResyncReq{
		// ACLs is a list af all access lists that are expected to be in VPP after RESYNC
		ACLs: []*acl.AccessLists_Acl{},
		// Interfaces is a list af all interfaces that are expected to be in VPP after RESYNC
		Interfaces: []*interfaces.Interfaces_Interface{},
		// SingleHopBFDSession is a list af all BFD sessions that are expected to be in VPP after RESYNC
		SingleHopBFDSession: []*bfd.SingleHopBFD_Session{},
		// SingleHopBFDKey is a list af all BFD authentication keys that are expected to be in VPP after RESYNC
		SingleHopBFDKey: []*bfd.SingleHopBFD_Key{},
		// SingleHopBFDEcho is a list af all BFD echo functions that are expected to be in VPP after RESYNC
		SingleHopBFDEcho: []*bfd.SingleHopBFD_EchoFunction{},
		// BridgeDomains is a list af all BDs that are expected to be in VPP after RESYNC
		BridgeDomains: []*l2.BridgeDomains_BridgeDomain{},
		// FibTableEntries is a list af all FIBs that are expected to be in VPP after RESYNC
		FibTableEntries: []*l2.FibTableEntries_FibTableEntry{},
		// XConnects is a list af all XCons that are expected to be in VPP after RESYNC
		XConnects: []*l2.XConnectPairs_XConnectPair{},
		// StaticRoutes is a list af all Static Routes that are expected to be in VPP after RESYNC
		StaticRoutes: []*l3.StaticRoutes_Route{}}
}

// delegates resync request to ifplugin/l2plugin/l3plugin resync requests (in this particular order)
func (plugin *Plugin) resyncConfigPropageRequest(req *DataResyncReq) error {
	log.DefaultLogger().Info("resync the VPP Configuration begin")
	startTime := time.Now()
	plugin.ifConfigurator.Resync(req.Interfaces)
	plugin.aclConfigurator.Resync(req.ACLs)
	plugin.bfdConfigurator.ResyncAuthKey(req.SingleHopBFDKey)
	plugin.bfdConfigurator.ResyncSession(req.SingleHopBFDSession)
	plugin.bfdConfigurator.ResyncEchoFunction(req.SingleHopBFDEcho)
	plugin.bdConfigurator.Resync(req.BridgeDomains)
	plugin.fibConfigurator.Resync(req.FibTableEntries)
	plugin.xcConfigurator.Resync(req.XConnects)
	plugin.routeConfigurator.Resync(req.StaticRoutes)

	vppResync := time.Since(startTime)
	log.DefaultLogger().WithField("durationInNs", vppResync.Nanoseconds()).Info("resync the VPP Configuration end")
{'fraction_non_alphanumeric': 0.08063843104527436, 'fraction_numerical': 0.004590027122887545, 'mean_word_length': 4.747601918465228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3296095', 'n_tokens_mistral': 3203, 'n_tokens_neox': 3053, 'n_words': 1008}