[hyperscan][pkg-config] hyperscan 从0到1路线图
经过一系列的研究学习,知识储备之后,终于,可以开始研究hyperscan了。
[knowledge][模式匹配] 字符匹配/模式匹配 正则表达式 自动机
[knowledge][perl][pcre][sed] sed / PCRE 语法/正则表达式
[development][PCRE] PCRE
----------------------------------------------------------------------
Now, let‘s hyperscan! 2333333
中文介绍:https://www.sdnlab.com/18773.html
官网: https://01.org/zh/hyperscan
正式入口:https://github.com/intel/hyperscan
开发者手册:http://intel.github.io/hyperscan/dev-reference/preface.html
官方例子程序:在源码的 examples/ 子目录。
其中用到了一个比较特殊的依赖库: Ragel http://www.colm.net/open-source/ragel/
Understanding the formal relationship between regular expressions and deterministic finite automata is key to using Ragel effectively.
理解正则表达式与确定有限状态自动机之间的关系,是用好这个库的关键。
提一个题外的编译系统 Ninja https://ninja-build.org/
编译一下:
┬─[tong@T7:~/Src/thirdparty/github]─[:: PM]
╰─>$ git clone git@github.com:intel/hyperscan.git
┬─[tong@T7:~/Src/thirdparty/github]─[:: PM]
╰─>$ cd hyperscan/
┬─[tong@T7:~/Src/thirdparty/github/hyperscan]─[:: PM]
╰─>$ mkdir BUILD
[root@dpdk hyperscan]# cd BUILD/
编译之前,需要安装boost,或者下载boost的源码。 仅在编译的时候需要boost的头文件而已,并不需要编译boost,也不需要安装boost的运行时库。
┬─[tong@T7:~/Src/thirdparty]─[:: PM]
╰─>$ wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2
┬─[tong@T7:~/Src/thirdparty]─[:: PM]
╰─>$ tar jxf boost_1_66_0.tar.bz2
还需有安装 Ragel-devel
[root@dpdk BUILD]# yum install ragel-devel
开始编译:
[root@dpdk BUILD]# cmake -DBOOST_ROOT=~/src/thirdparty/boost_1_66_0/ ../
[root@dpdk BUILD]# cmake --build .
[root@dpdk BUILD]# make
测试编译是否成功:
[root@dpdk BUILD]# ./bin/unit-hyperscan
读开发手册:http://intel.github.io/hyperscan/dev-reference/
备注:
模糊匹配之
莱文斯坦距离:https://zh.wikipedia.org/wiki/萊文斯坦距離
汉明距离:https://zh.wikipedia.org/wiki/%E6%B1%89%E6%98%8E%E8%B7%9D%E7%A6%BB
API:http://intel.github.io/hyperscan/dev-reference/api_files.html
指定安装路径:
[root@dpdk BUILD]# cmake -DCMAKE_INSTALL_PREFIX=~/src/thirdparty/github/hyperscan/BUILD/DIST/ ../
[root@dpdk BUILD]# make
[root@dpdk BUILD]# make install
安装后的内容:
[root@dpdk DIST]# tree
.
├── include
│ └── hs
│ ├── hs_common.h
│ ├── hs_compile.h
│ ├── hs.h
│ └── hs_runtime.h
├── lib64
│ ├── libhs.a
│ ├── libhs_runtime.a
│ └── pkgconfig
│ └── libhs.pc
└── share
└── doc
└── hyperscan
└── examples
├── patbench.cc
├── pcapscan.cc
├── README.md
└── simplegrep.c directories, files
例子: share/doc/hyperscan/examples/simplegrep.c
编译:
gcc -o simplegrep simplegrep.c $(pkg-config --cflags --libs libhs)
引申内容:pkt-config
介绍:https://zh.wikipedia.org/wiki/Pkg-config
主页:https://www.freedesktop.org/wiki/Software/pkg-config/
On most systems, pkg-config looks in /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkg‐
config and /usr/local/share/pkgconfig for these files. It will additionally look in the colon-separated (on Windows,
semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable.
默认情况下,pkg-config会到以下四个目录中查找,/usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkg‐config and /usr/local/share/pkgconfig
之后,还会查找环境变量PKG_CONFIG_PATH 中的路径。
因为,我的hyperscan 没有安装在标准路径下,所以:
[tong@T7 pkgconfig]$ export PKG_CONFIG_PATH=~/Src/thirdparty/github/hyperscan/BUILD/DIST/lib64/pkgconfig
[tong@T7 pkgconfig]$ pkg-config --cflags --libs libhs
-I/root/src/thirdparty/github/hyperscan/BUILD/DIST/include/hs -L/root/src/thirdparty/github/hyperscan/BUILD/DIST/lib -lhs
[tong@T7 pkgconfig]$
增加一个软链接:
[root@dpdk DIST]# ln -rfs lib64/ lib
[root@dpdk DIST]# ll
total
drwxr-xr-x root root Jan : include
lrwxrwxrwx root root Jan : lib -> lib64
drwxr-xr-x root root Jan : lib64
drwxr-xr-x root root Jan : share
[root@dpdk DIST]#
编译:
[root@dpdk examples]# cat build.sh
#! /usr/bin/bash export PKG_CONFIG_PATH=/root/src/thirdparty/github/hyperscan/BUILD/DIST/lib64/pkgconfig
g++ -o simplegrep simplegrep.c $(pkg-config --cflags --libs libhs)
测试运行:
[root@dpdk examples]# ./simplegrep init simplegrep.c
Scanning bytes with Hyperscan
[root@dpdk examples]#
块内容模式匹配的例子:
https://github.com/tony-caotong/knickknack/tree/master/examples/hyperscan
效果如下:
[root@dpdk hyperscan]# ./test
Usage: ./test <pattern> <string>
[root@dpdk hyperscan]# ./test dafkj1234dlkfajf
id: , matched position:
[root@dpdk hyperscan]# ./test dafkj1234dl1234kfajf
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]#
查看例子源码,修改编译,可以做多模式匹配:
默认的两个pattern为 1234, 5678
效果如下:
[root@dpdk hyperscan]# ./test ""
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]# ./test "dfasfdsaf1234gadgdgdahg5678"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]# ./test "dfasfdsaf1234gadgdgdahg5678dfsag"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]#
修改例子中的宏,可以开启流匹配模式
默认的两个pattern为1234,5678. 运行时的俩个参数可以组合成一个流。
效果如下:
[root@dpdk hyperscan]# ./test "dfasfdsaf1234gad" "gdgdahg5678dfsag"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]# ./test "dfasfdsaf123" "4gadgdgdahg5678dfsag"
id: , matched position:
id: , matched position:
[root@dpdk hyperscan]#
continue:
[hyperscan] hyperscan 1到1.5 --!!
[hyperscan][pkg-config] hyperscan 从0到1路线图的更多相关文章
- 【hyperscan】编译hyperscan 4.0.0
ref: http://01org.github.io/hyperscan/dev-reference/getting_started.html 1. 硬件需求 intel x86处理器 64-bit ...
- [hyperscan] hyperscan 1到1.5 --!!
[hyperscan][pkg-config] hyperscan 从0到1路线图 接续前文,继续深入理解: 概述: 1. 自动机理论,是hyperscan的理论基础. https://zh.wik ...
- Hyperscan与Snort的集成方案
概况 Hyperscan作为一款高性能的正则表达式匹配库,非常适用于部署在诸如DPI/IPS/IDS/NGFW等网络解决方案中.Snort (https://www.snort.org) 是目前应用最 ...
- anaconda2下面安装opencv2.4.13.4完成----解决默认安装的问题----Thefunction is not implemented. Rebuild the library with Windows, GTK+ 2.x orCarbon support. If you are on Ubuntu or Debian, install libgtk2.0‑dev and pkg
转载自:http://blog.csdn.net/qingyanyichen/article/details/73550924 本人下载编译安装了opencv2.4.9,oppencv2.4.10,o ...
- 如何在windows下成功的编译和安装python组件hyperscan
摘要:hyperscan 是英特尔推出的一款高性能正则表达式引擎,一次接口调用可以实现多条规则与多个对象之间的匹配,可以支持多种匹配模式,块模式和流模式,它是以PCRE为原型开发,并以BSD许可证开源 ...
- OpenShift Container Platform 4.3.0部署实录
本文参照红帽官方文档,在裸机安装Openshift4.3文档进行.因为只有一台64G内存的PC机,安装vmware vsphere 6.7免费版进行本测试,所以尝试在OCP官方文档要求的最低内存需求基 ...
- yoyogo v1.7.4 发布,支持 grpc v1.3.8 & etcd 3.5.0
YoyoGo (Go语言框架)一个简单.轻量.快速.基于依赖注入的微服务框架( web .grpc ),支持Nacos/Consoul/Etcd/Eureka/k8s /Apollo等 . https ...
- 跨平台日志清理工具 Log-Cutter v2.0.1 正式发布
Log-Cutter 是JessMA开源组织开发的一个简单实用的日志切割清理工具.对于服务器的日常维护来说,日志清理是非常重要的事情,如果残留日志过多则严重浪费磁盘空间同时影响服务的性能.如果用手工方 ...
- ExtJS 中类的选项 - config
首先看一个例子,我们在ExtJS中定义一个Window对象,代码如下: var win = Ext.create("Ext.window.Window", { title: '示例 ...
随机推荐
- Atiit 常见功能 常用功能与模块的最快速解决方案
Atiit 常见功能 常用功能与模块的最快速解决方案 一.大力使用第三方API接口 一.导出excel jquery.table2excel 二.Form表单验证,使用h5验证属性 验证发生在form ...
- 使用vw做移动端页面的适配
Flexible到今天也有几年的历史了,解救了很多同学针对于H5页面布局的适配问题.而这套方案也相对而言是一个较为成熟的方案.简单的回忆一下,当初为了能让页面更好的适配各种不同的终端,通过Hack手段 ...
- JAVA(三)JAVA常用类库/JAVA IO
成鹏致远 | lcw.cnblog.com |2014-02-01 JAVA常用类库 1.StringBuffer StringBuffer是使用缓冲区的,本身也是操作字符串的,但是与String类不 ...
- 在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求(转)
通用辅助类 下面是我编写的一个辅助类,在这个类中采用了HttpWebRequest中发送GET/HTTP/HTTPS请求,因为有的时候需要获取认证信息(如Cookie),所以返回的是HttpWebRe ...
- Redis系统性介绍
虽然Redis已经很火了,相信还是有很多同学对Redis只是有所听闻或者了解并不全面,下面是一个比较系统的Redis介绍,对Redis的特性及各种数据类型及操作进行了介绍.是一个很不错的Redis入门 ...
- Secure backup
Secure backup 安全备份软件 安全备份软件致力于提供一款开源免费的安全云备份软件,支持文件管理,文件自动同步到云盘,增量备份等功能. 目前正在开发过程中...
- Kubernetes集群部署之三ETCD集群部署
kuberntes 系统使用 etcd 存储所有数据,本文档介绍部署一个三节点高可用 etcd 集群的步骤,这三个节点复用 kubernetes 集群机器k8s-master.k8s-node-1.k ...
- hibernate 查询全部数据的三种方法
1.Query对象 使用Query对象需要写hql语句,使用hql语句操作的是实体类和属性. 用于查询全部的hql语句:from 实体类名称 例:String hql = "from U ...
- 使用InstallAnywhere7.1制作Java exe程序安装包
[转[使用InstallAnywhere7.1制作Java exe程序安装包 使用InstallAnywhere7.1制作Java exe程序安装包 对于已经完成的Java应用程序开发项目,从商业化角 ...
- Mac zsh切换bash bash切换zsh
切换bash ————>>>chsh -s /bin/bash 切换zsh ------->>>chsh -s /bin/zsh