You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/07/12 15:10:11 UTC
[plc4x] 01/03: feat(plc4go/plc4xpcapanalyzer): added more options to cbus
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 95c80a8a40868397906d36f0da41c2c0f1ae7c07
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Jul 12 12:05:58 2022 +0200
feat(plc4go/plc4xpcapanalyzer): added more options to cbus
---
plc4go/tools/plc4xpcapanalyzer/cmd/analyze.go | 46 ++++---------
plc4go/tools/plc4xpcapanalyzer/cmd/bacnet.go | 70 +++++++++++++++++++
plc4go/tools/plc4xpcapanalyzer/cmd/cbus.go | 80 ++++++++++++++++++++++
plc4go/tools/plc4xpcapanalyzer/cmd/root.go | 24 +++----
.../plc4xpcapanalyzer/config/AnalyzeConfig.go | 35 ++++++++++
.../tools/plc4xpcapanalyzer/config/BacnetConfig.go | 31 +++++++++
.../tools/plc4xpcapanalyzer/config/CBusConfig.go | 41 +++++++++++
.../tools/plc4xpcapanalyzer/config/RootConfig.go | 29 ++++++++
.../internal/analyzer/analyzer.go | 25 +++----
.../internal/cbusanalyzer/analyzer.go | 3 +-
10 files changed, 324 insertions(+), 60 deletions(-)
diff --git a/plc4go/tools/plc4xpcapanalyzer/cmd/analyze.go b/plc4go/tools/plc4xpcapanalyzer/cmd/analyze.go
index fe004740b..34226daeb 100644
--- a/plc4go/tools/plc4xpcapanalyzer/cmd/analyze.go
+++ b/plc4go/tools/plc4xpcapanalyzer/cmd/analyze.go
@@ -20,9 +20,9 @@
package cmd
import (
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/config"
"github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/internal/analyzer"
"github.com/pkg/errors"
- "github.com/rs/zerolog/log"
"math"
"os"
@@ -34,16 +34,6 @@ var validProtocolType = map[string]interface{}{
"c-bus": nil,
}
-// flags here
-var (
- filter string
- noFilter, onlyParse, noBytesCompare bool
- client string
- bacnetFilter string
- startPackageNumber uint
- packageNumberLimit uint
-)
-
// analyzeCmd represents the analyze command
var analyzeCmd = &cobra.Command{
Use: "analyze [protocolType] [pcapfile]",
@@ -67,18 +57,7 @@ TODO: document me
Run: func(cmd *cobra.Command, args []string) {
protocolType := args[0]
pcapFile := args[1]
- if !noFilter {
- switch protocolType {
- case "bacnet":
- if filter != "" && bacnetFilter != "" {
- log.Debug().Str("filter", filter).Msg("Setting bacnet filter")
- filter = bacnetFilter
- }
- }
- } else {
- log.Info().Msg("All filtering disabled")
- }
- analyzer.Analyze(pcapFile, protocolType, filter, onlyParse, noBytesCompare, client, startPackageNumber, packageNumberLimit, verbosity)
+ analyzer.Analyze(pcapFile, protocolType)
println("Done")
},
}
@@ -86,14 +65,15 @@ TODO: document me
func init() {
rootCmd.AddCommand(analyzeCmd)
- analyzeCmd.Flags().StringVarP(&filter, "filter", "f", "", "BFF filter to apply")
- analyzeCmd.Flags().BoolVarP(&noFilter, "no-filter", "n", false, "disable filter")
- analyzeCmd.Flags().BoolVarP(&onlyParse, "onlyParse", "o", false, "only parse messaged")
- analyzeCmd.Flags().BoolVarP(&noBytesCompare, "noBytesCompare", "b", false, "don't compare original bytes with serialized bytes")
- analyzeCmd.Flags().StringVarP(&client, "client", "c", "", "The client ip (this is useful for protocols where request/response is different e.g. modbus, cbus)")
- analyzeCmd.Flags().UintVarP(&startPackageNumber, "startPackageNumber", "s", 0, "Defines with what package number should be started")
- analyzeCmd.Flags().UintVarP(&packageNumberLimit, "packageNumberLimit", "l", math.MaxUint, "Defines how many packages should be parsed")
- // TODO: maybe it is smarter to convert this into subcommands because this option is only relevant to bacnet
- analyzeCmd.PersistentFlags().StringVarP(&bacnetFilter, "default-bacnet-filter", "", "udp port 47808 and udp[4:2] > 29", "Defines the default filter when bacnet is selected")
- // TODO: support other protocols
+ addAnalyzeFlags(analyzeCmd)
+}
+
+func addAnalyzeFlags(command *cobra.Command) {
+ command.Flags().StringVarP(&config.AnalyzeConfigInstance.Filter, "filter", "f", "", "BFF filter to apply")
+ command.Flags().BoolVarP(&config.AnalyzeConfigInstance.NoFilter, "no-filter", "n", false, "disable filter")
+ command.Flags().BoolVarP(&config.AnalyzeConfigInstance.OnlyParse, "onlyParse", "o", false, "only parse messaged")
+ command.Flags().BoolVarP(&config.AnalyzeConfigInstance.NoBytesCompare, "noBytesCompare", "b", false, "don't compare original bytes with serialized bytes")
+ command.Flags().StringVarP(&config.AnalyzeConfigInstance.Client, "client", "c", "", "The client ip (this is useful for protocols where request/response is different e.g. modbus, cbus)")
+ command.Flags().UintVarP(&config.AnalyzeConfigInstance.StartPackageNumber, "startPackageNumber", "s", 0, "Defines with what package number should be started")
+ command.Flags().UintVarP(&config.AnalyzeConfigInstance.PackageNumberLimit, "packageNumberLimit", "l", math.MaxUint, "Defines how many packages should be parsed")
}
diff --git a/plc4go/tools/plc4xpcapanalyzer/cmd/bacnet.go b/plc4go/tools/plc4xpcapanalyzer/cmd/bacnet.go
new file mode 100644
index 000000000..6398fcb3c
--- /dev/null
+++ b/plc4go/tools/plc4xpcapanalyzer/cmd/bacnet.go
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 cmd
+
+import (
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/config"
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/internal/analyzer"
+ "github.com/pkg/errors"
+ "github.com/rs/zerolog/log"
+ "os"
+
+ "github.com/spf13/cobra"
+)
+
+// bacnetCmd represents the bacnet command
+var bacnetCmd = &cobra.Command{
+ Use: "bacnet [pcapfile]",
+ Short: "analyzes a pcap file using a bacnet driver",
+ Long: `Analyzes a pcap file using a bacnet driver
+TODO: document me
+`,
+ Args: func(cmd *cobra.Command, args []string) error {
+ if len(args) < 1 {
+ return errors.New("requires exactly one arguments")
+ }
+ pcapFile := args[0]
+ if _, err := os.Stat(pcapFile); errors.Is(err, os.ErrNotExist) {
+ return errors.Errorf("Pcap file not found %s", pcapFile)
+ }
+ return nil
+ },
+ Run: func(cmd *cobra.Command, args []string) {
+ pcapFile := args[0]
+ if !config.BacnetConfigInstance.NoFilter {
+ if config.BacnetConfigInstance.Filter != "" && config.BacnetConfigInstance.BacnetFilter != "" {
+ log.Debug().Str("filter", config.BacnetConfigInstance.Filter).Msg("Setting bacnet filter")
+ config.BacnetConfigInstance.Filter = config.BacnetConfigInstance.BacnetFilter
+ }
+ } else {
+ log.Info().Msg("All filtering disabled")
+ }
+ analyzer.Analyze(pcapFile, "bacnet")
+ println("Done")
+ },
+}
+
+func init() {
+ analyzeCmd.AddCommand(bacnetCmd)
+
+ bacnetCmd.PersistentFlags().StringVarP(&config.BacnetConfigInstance.BacnetFilter, "default-bacnet-filter", "", "udp port 47808 and udp[4:2] > 29", "Defines the default filter when bacnet is selected")
+
+ addAnalyzeFlags(bacnetCmd)
+}
diff --git a/plc4go/tools/plc4xpcapanalyzer/cmd/cbus.go b/plc4go/tools/plc4xpcapanalyzer/cmd/cbus.go
new file mode 100644
index 000000000..156dd230e
--- /dev/null
+++ b/plc4go/tools/plc4xpcapanalyzer/cmd/cbus.go
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 cmd
+
+import (
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/config"
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/internal/analyzer"
+ "github.com/pkg/errors"
+ "github.com/rs/zerolog/log"
+ "os"
+
+ "github.com/spf13/cobra"
+)
+
+// cbusCmd represents the cbus command
+var cbusCmd = &cobra.Command{
+ Use: "c-bus [pcapfile]",
+ Short: "analyzes a pcap file using a c-bus driver",
+ Long: `Analyzes a pcap file using a c-bus driver
+TODO: document me
+`,
+ Args: func(cmd *cobra.Command, args []string) error {
+ if len(args) < 1 {
+ return errors.New("requires exactly one arguments")
+ }
+ pcapFile := args[0]
+ if _, err := os.Stat(pcapFile); errors.Is(err, os.ErrNotExist) {
+ return errors.Errorf("Pcap file not found %s", pcapFile)
+ }
+ return nil
+ },
+ Run: func(cmd *cobra.Command, args []string) {
+ pcapFile := args[0]
+ if !config.CBusConfigInstance.NoFilter {
+ if config.CBusConfigInstance.Filter != "" && config.CBusConfigInstance.CBusFilter != "" {
+ log.Debug().Str("filter", config.CBusConfigInstance.Filter).Msg("Setting cbus filter")
+ config.CBusConfigInstance.Filter = config.CBusConfigInstance.CBusFilter
+ }
+ } else {
+ log.Info().Msg("All filtering disabled")
+ }
+ analyzer.Analyze(pcapFile, "c-bus")
+ println("Done")
+ },
+}
+
+func init() {
+ analyzeCmd.AddCommand(cbusCmd)
+
+ cbusCmd.PersistentFlags().StringVarP(&config.CBusConfigInstance.CBusFilter, "default-cbus-filter", "", "udp port 10001", "Defines the default filter when c-bus is selected")
+
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Connect, "cbus-connect", "", false, "Defines that SAL messages can occur at any time")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Smart, "cbus-smart", "", false, "Disable echo of characters. When used with connect SAL have a long option. Select long from of most CAL replies")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Idmon, "cbus-idmon", "", false, "only works with smart. Select long form of CAL messages")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Exstat, "cbus-exstat", "", false, "useful with smart. Select long form, extended format for all monitored and initiated status requests")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Monitor, "cbus-monitor", "", false, "monitors all traffic for status requests. Status requests will be returned as CAL. Replies are modified by exstat. Usually used in conjunction with connect.")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Monall, "cbus-monall", "", false, "Same as connect. In addition it will return remote network SAL")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Pun, "cbus-pun", "", false, "Serial interface will emit a power up notification")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Pcn, "cbus-pcn", "", false, "causes parameter change notifications to be emitted.")
+ cbusCmd.Flags().BoolVarP(&config.CBusConfigInstance.Srchk, "cbus-srchk", "", false, "enabled the crc checks")
+
+ addAnalyzeFlags(cbusCmd)
+}
diff --git a/plc4go/tools/plc4xpcapanalyzer/cmd/root.go b/plc4go/tools/plc4xpcapanalyzer/cmd/root.go
index 3996ff458..dddde4b9b 100644
--- a/plc4go/tools/plc4xpcapanalyzer/cmd/root.go
+++ b/plc4go/tools/plc4xpcapanalyzer/cmd/root.go
@@ -21,6 +21,7 @@ package cmd
import (
"fmt"
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/config"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
@@ -30,11 +31,6 @@ import (
"github.com/spf13/viper"
)
-var cfgFile string
-var logType string
-var logLevel string
-var verbosity int
-
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "plc4xpcapanalyzer",
@@ -57,19 +53,19 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
- rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.plc4xpcapanalyzer.yaml)")
- rootCmd.PersistentFlags().StringVar(&logType, "log-type", "text", "define how the log will be evaluated")
- rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "off", "define the log Level")
- rootCmd.PersistentFlags().CountVarP(&verbosity, "verbose", "v", "counted verbosity")
+ rootCmd.PersistentFlags().StringVar(&config.RootConfigInstance.CfgFile, "config", "", "config file (default is $HOME/.plc4xpcapanalyzer.yaml)")
+ rootCmd.PersistentFlags().StringVar(&config.RootConfigInstance.LogType, "log-type", "text", "define how the log will be evaluated")
+ rootCmd.PersistentFlags().StringVar(&config.RootConfigInstance.LogLevel, "log-level", "off", "define the log Level")
+ rootCmd.PersistentFlags().CountVarP(&config.RootConfigInstance.Verbosity, "verbose", "v", "counted verbosity")
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
- if cfgFile != "" {
+ if config.RootConfigInstance.CfgFile != "" {
// Use config file from the flag.
- viper.SetConfigFile(cfgFile)
+ viper.SetConfigFile(config.RootConfigInstance.CfgFile)
} else {
// Find home directory.
home, err := os.UserHomeDir()
@@ -89,7 +85,7 @@ func initConfig() {
}
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
- if logType == "text" {
+ if config.RootConfigInstance.LogType == "text" {
log.Logger = log.
//// Enable below if you want to see the filenames
//With().Caller().Logger().
@@ -99,9 +95,9 @@ func initConfig() {
}
func parseLogLevel() zerolog.Level {
- level, err := zerolog.ParseLevel(logLevel)
+ level, err := zerolog.ParseLevel(config.RootConfigInstance.LogLevel)
if err != nil {
- log.Fatal().Err(err).Msgf("Unknown log level %s", logLevel)
+ log.Fatal().Err(err).Msgf("Unknown log level %s", config.RootConfigInstance.LogLevel)
}
return level
}
diff --git a/plc4go/tools/plc4xpcapanalyzer/config/AnalyzeConfig.go b/plc4go/tools/plc4xpcapanalyzer/config/AnalyzeConfig.go
new file mode 100644
index 000000000..4c4095851
--- /dev/null
+++ b/plc4go/tools/plc4xpcapanalyzer/config/AnalyzeConfig.go
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 config
+
+type AnalyzeConfig struct {
+ *RootConfig
+ Filter string
+ NoFilter, OnlyParse, NoBytesCompare bool
+ Client string
+ StartPackageNumber uint
+ PackageNumberLimit uint
+}
+
+var AnalyzeConfigInstance = AnalyzeConfig{}
+
+func init() {
+ AnalyzeConfigInstance.RootConfig = &RootConfigInstance
+}
diff --git a/plc4go/tools/plc4xpcapanalyzer/config/BacnetConfig.go b/plc4go/tools/plc4xpcapanalyzer/config/BacnetConfig.go
new file mode 100644
index 000000000..de370e415
--- /dev/null
+++ b/plc4go/tools/plc4xpcapanalyzer/config/BacnetConfig.go
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 config
+
+type BacnetConfig struct {
+ *AnalyzeConfig
+ BacnetFilter string
+}
+
+var BacnetConfigInstance = BacnetConfig{}
+
+func init() {
+ BacnetConfigInstance.AnalyzeConfig = &AnalyzeConfigInstance
+}
diff --git a/plc4go/tools/plc4xpcapanalyzer/config/CBusConfig.go b/plc4go/tools/plc4xpcapanalyzer/config/CBusConfig.go
new file mode 100644
index 000000000..f9d1b3e5c
--- /dev/null
+++ b/plc4go/tools/plc4xpcapanalyzer/config/CBusConfig.go
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 config
+
+type CBusConfig struct {
+ *AnalyzeConfig
+ CBusFilter string
+
+ Connect bool
+ Smart bool
+ Idmon bool
+ Exstat bool
+ Monitor bool
+ Monall bool
+ Pun bool
+ Pcn bool
+ Srchk bool
+}
+
+var CBusConfigInstance = CBusConfig{}
+
+func init() {
+ CBusConfigInstance.AnalyzeConfig = &AnalyzeConfigInstance
+}
diff --git a/plc4go/tools/plc4xpcapanalyzer/config/RootConfig.go b/plc4go/tools/plc4xpcapanalyzer/config/RootConfig.go
new file mode 100644
index 000000000..56bacdb69
--- /dev/null
+++ b/plc4go/tools/plc4xpcapanalyzer/config/RootConfig.go
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 config
+
+type RootConfig struct {
+ CfgFile string
+ LogType string
+ LogLevel string
+ Verbosity int
+}
+
+var RootConfigInstance = RootConfig{}
diff --git a/plc4go/tools/plc4xpcapanalyzer/internal/analyzer/analyzer.go b/plc4go/tools/plc4xpcapanalyzer/internal/analyzer/analyzer.go
index 6eccceaa9..d5fd8f43e 100644
--- a/plc4go/tools/plc4xpcapanalyzer/internal/analyzer/analyzer.go
+++ b/plc4go/tools/plc4xpcapanalyzer/internal/analyzer/analyzer.go
@@ -23,6 +23,7 @@ import (
"bytes"
"encoding/hex"
"fmt"
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/config"
"github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/internal/bacnetanalyzer"
"github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer"
"github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/internal/common"
@@ -34,10 +35,10 @@ import (
"net"
)
-func Analyze(pcapFile, protocolType, filter string, onlyParse, noBytesCompare bool, client string, startPackageNumber, packageNumberLimit uint, verbosity int) {
- log.Info().Msgf("Analyzing pcap file '%s' with protocolType '%s' and filter '%s' now", pcapFile, protocolType, filter)
+func Analyze(pcapFile, protocolType string) {
+ log.Info().Msgf("Analyzing pcap file '%s' with protocolType '%s' and filter '%s' now", pcapFile, protocolType, config.AnalyzeConfigInstance.Filter)
- handle, numberOfPackage, timestampToIndexMap := pcaphandler.GetIndexedPcapHandle(pcapFile, filter)
+ handle, numberOfPackage, timestampToIndexMap := pcaphandler.GetIndexedPcapHandle(pcapFile, config.AnalyzeConfigInstance.Filter)
log.Info().Msgf("Starting to analyze %d packages", numberOfPackage)
defer handle.Close()
log.Debug().Interface("handle", handle).Int("numberOfPackage", numberOfPackage).Msg("got handle")
@@ -52,7 +53,7 @@ func Analyze(pcapFile, protocolType, filter string, onlyParse, noBytesCompare bo
packageParse = bacnetanalyzer.PackageParse
serializePackage = bacnetanalyzer.SerializePackage
case "c-bus":
- analyzer := cbusanalyzer.Analyzer{Client: net.ParseIP(client)}
+ analyzer := cbusanalyzer.Analyzer{Client: net.ParseIP(config.AnalyzeConfigInstance.Client)}
packageParse = analyzer.PackageParse
serializePackage = analyzer.SerializePackage
prettyPrint = analyzer.PrettyPrint
@@ -75,12 +76,12 @@ func Analyze(pcapFile, protocolType, filter string, onlyParse, noBytesCompare bo
compareFails := 0
for packet := range source.Packets() {
currentPackageNum++
- if currentPackageNum < startPackageNumber {
- log.Debug().Msgf("Skipping package number %d (till no. %d)", currentPackageNum, startPackageNumber)
+ if currentPackageNum < config.AnalyzeConfigInstance.StartPackageNumber {
+ log.Debug().Msgf("Skipping package number %d (till no. %d)", currentPackageNum, config.AnalyzeConfigInstance.StartPackageNumber)
continue
}
- if currentPackageNum > packageNumberLimit {
- log.Warn().Msgf("Aborting reading packages because we hit the limit of %d", packageNumberLimit)
+ if currentPackageNum > config.AnalyzeConfigInstance.PackageNumberLimit {
+ log.Warn().Msgf("Aborting reading packages because we hit the limit of %d", config.AnalyzeConfigInstance.PackageNumberLimit)
break
}
if packet == nil {
@@ -116,10 +117,10 @@ func Analyze(pcapFile, protocolType, filter string, onlyParse, noBytesCompare bo
continue
} else {
log.Info().Stringer("packetInformation", packetInformation).Msgf("No.[%d] Parsed", realPacketNumber)
- if verbosity > 1 {
+ if config.AnalyzeConfigInstance.Verbosity > 1 {
prettyPrint(parsed)
}
- if onlyParse {
+ if config.AnalyzeConfigInstance.OnlyParse {
log.Trace().Msg("only parsing")
continue
}
@@ -130,7 +131,7 @@ func Analyze(pcapFile, protocolType, filter string, onlyParse, noBytesCompare bo
log.Warn().Stringer("packetInformation", packetInformation).Err(err).Msgf("No.[%d] Error serializing", realPacketNumber)
continue
}
- if noBytesCompare {
+ if config.AnalyzeConfigInstance.NoBytesCompare {
log.Trace().Msg("not comparing bytes")
continue
}
@@ -138,7 +139,7 @@ func Analyze(pcapFile, protocolType, filter string, onlyParse, noBytesCompare bo
compareFails++
// TODO: write report to xml or something
log.Warn().Stringer("packetInformation", packetInformation).Msgf("No.[%d] Bytes don't match", realPacketNumber)
- if verbosity > 0 {
+ if config.AnalyzeConfigInstance.Verbosity > 0 {
println("Original bytes")
println(hex.Dump(payload))
println("Serialized bytes")
diff --git a/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go b/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go
index 36b223db2..f7d55f704 100644
--- a/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go
+++ b/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go
@@ -23,6 +23,7 @@ import (
"fmt"
"github.com/apache/plc4x/plc4go/internal/spi/utils"
"github.com/apache/plc4x/plc4go/protocols/cbus/readwrite/model"
+ "github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/config"
"github.com/apache/plc4x/plc4go/tools/plc4xpcapanalyzer/internal/common"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
@@ -40,7 +41,7 @@ func (a *Analyzer) PackageParse(packetInformation common.PacketInformation, payl
if !a.initialized {
log.Warn().Msg("Not initialized... doing that now")
a.requestContext = model.NewRequestContext(false, false, false)
- a.cBusOptions = model.NewCBusOptions(false, false, false, false, false, false, false, false, false)
+ a.cBusOptions = model.NewCBusOptions(config.CBusConfigInstance.Connect, config.CBusConfigInstance.Smart, config.CBusConfigInstance.Idmon, config.CBusConfigInstance.Exstat, config.CBusConfigInstance.Monitor, config.CBusConfigInstance.Monall, config.CBusConfigInstance.Pun, config.CBusConfigInstance.Pcn, config.CBusConfigInstance.Srchk)
a.initialized = true
}
log.Debug().Msgf("Parsing %s with requestContext\n%v\nBusOptions\n%s", packetInformation, a.requestContext, a.cBusOptions)