[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: '示例 ...
随机推荐
- 【转】css3实现文字闪烁,改变透明度
<style> @-webkit-keyframes shake{ 0%{ opacity: 1; } 50%{ opacity: 0.5; } 100%{ opacity: 1; } } ...
- iOS应用开发,全局强制竖屏,部分页面允许旋转的处理
目前大多数app都不支持横屏模式,用户不常用,开发起来也麻烦一些.但有些时候,又离不开横屏和竖屏的切换,比如查看视频.图片.文档等,这时又不得不对页面做横屏的处理.下面来教大家如何处理这种场景,方法可 ...
- 去除partner页面消息 自动添加关注者的功能
某些公司希望在partner页面说些partner的坏话,可是odoo居然自动添加了partner关注,这就尴尬了.... 如果恰搭建了邮件服务器,很有可能就自动发到了客户邮箱里,等着炸锅吧.... ...
- oneinstack 另一个 lnmp环境一键安装工具
oneinstack 另一个 http://oneinstack.com/ OneinStack包含以下组合: lnmp(Linux + Nginx+ MySQL+ PHP) lamp(Linux ...
- fputc和putc和putchar函数的用法
功 能: 输出一字符到指定流中 putc()与fputc()等价.不同之处为:当putc函数被定义为宏时,它可能多次计算stream的值. 关于fputc(): 原型:int fputc(char c ...
- Tomcat容器做到自我保护,设置最大连接数(服务限流:tomcat请求数限制)
http://itindex.net/detail/58707-%E5%81%87%E6%AD%BB-tomcat-%E5%AE%B9%E5%99%A8 为了确保服务不会被过多的http长连接压垮,我 ...
- 设计模式 -创建型模式 ,python工厂模式 抽象工厂模式(1)
工厂模式 import xml.etree.ElementTree as etree import json class JSONConnector: def __init__(self, filep ...
- [IR] Suffix Trees and Suffix Arrays
前缀树 匹配前缀字符串是不言自明的道理. 1. 字符串的快速检索 2. 最长公共前缀(LCP) 等等 树的压缩 后缀树 Let s=abab, a suffix tree of s is a comp ...
- Python version 2.7 required, which was not found in the registry解决方法
转自:https://blog.csdn.net/zklth/article/details/8117207 新建一个register.py文件,执行该文件,完成python的注册. import s ...
- ehcache缓存配置与参数说明
<diskStore path="java.io.tmpdir" /> <defaultCache eternal="false" maxEl ...