packetC Programming

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

This book introduces the tools you'll need to program with the packetC language.

packetC speeds the development of applications that live within computer networks, the kind of programs that provide network functionality for connecting "clients" and "servers” and “clouds." The simplest examples provide packet switching and routing while more complex examples implement cyber security, broadband policies or cloud-based network infrastructure.

Network applications, such as those processing digital voice and video, must be highly scalable, secure and maintainable. Such application requirements translate to requirements for a network programming language that leverages massively-parallel systems and ensures a high level of security, while representing networking protocols and transactions in the simplest way possible.

packetC meets these requirements with an intuitive approach to coarse-grained parallelism, with strong-typing and controlled memory access for security and with new data types and operators that express the classic operations of the network-oriented world in familiar programming terms.

No other language has addressed the full breadth of requirements for tractable parallelism, secure processing and usable constructs.  The packetC language is growing in adoption and has been used to develop solutions operating in some of the world’s largest networks.

This important new language, packetC, has now been successfully documented in this book, in which the language's authors provide the materials and tools you'll need in a readable and accessible form.

What you’ll learn

This book is the primary document specifying the language from a developer’s point of view and act as the formal language user’s guide. It covers:

  • How to program applications in packetC.
  • The parallel programming model of packetC
  • Deviations from C99 and the unique aspects of packetC
  • How to leverage existing C code and the applicability of the C standard libraries

Who this book is for

packetC Programming is written for a wide variety of potential programmers. Most importantly, it's for people who need to use packetC to program for the Internet backbone. Still, knowledge of the packetC language will help a much wider array of programmers who need to write effective code that will be optimized for the cloud and work effectively and efficiently through complex network structures. Finally, readers will learn about how and why packetC is needed, and to better understand the technologies, standards and issues surrounding the 'net. If you really want to understand this level of programming, this book is a must-have!

Table of Contents

PART  1:        packetC Background
Chapter         1:        Origins of packetC
Chapter         2:        Introduction to packetC Language
Chapter         3:        Style Guidelines for packetC Programs
Chapter         4:        Construction of a packetC Program

PART  2:        Language Reference
Chapter         5:        Variables—Identifiers, Basic Scalar Data Types, and Literals  Chapter         6:        Data Initialization and Mathematical Expressions
Chapter         7:        Functions     
Chapter         8:        packetC Data Type Fundamentals
Chapter         9:        C-Style Data Types
Chapter         10:      Basic Packet Interaction and Operations
Chapter         11:      Selection Statements
Chapter         12:      Loops and Flow Control
Chapter         13:      Exception Handling
Chapter         14:      Databases Types and Operations  
Chapter         15:      Search Set Types and Operations          
Chapter         16:      Reference Type and Operations
Chapter         17:      Lock and Unlock Operators  
Chapter         18:      Packet Information Block and System Packet Operations Chapter         19:      Descriptor Type and Operations

PART  3:        Developing Applications
Chapter         20:      Control Plane and System Interaction
Chapter         21:      packetC Pre-Processor     
Chapter         22:      Pragmas and Other Key Compiler Directives
Chapter         23:      Developing Large Applications in packetC
Chapter         24:      Construction of a packetC Executable
Chapter         25:      packetC Standard Networking Descriptors
Chapter         26:      Developing For Performance
Chapter         27:      Standard Libraries

PART  4:        Industry Reprints

Appendix        A:      Reference Tables
Appendix        B:      Open Systems Vendors for packetC
Appendix        C:      Glossary
Appendix        D:      CloudShield Products Supporting packetC

Author(s): Peder Jungck, Ralph Duncan, Dwight Mulcahy
Edition: 1
Publisher: Apress
Year: 2011

Language: English
Pages: 464

Cover
......Page 429
Contents at a Glance
......Page 3
Contents
......Page 431
About the Authors
......Page 442
Acknowledgments
......Page 443
Introduction
......Page 5
packetC Background......Page 7
Origins of packetC......Page 8
Tenets of packetC......Page 10
Parallel Processing, Security, and Packet Orientation......Page 13
packetC Language Design Considerations......Page 14
packetC Language Similarities......Page 15
Virtual Machine—packetC Behavior......Page 16
Case Sensitivity and Identifiers......Page 17
Object Orientation and Control Flow......Page 18
Memory Layout......Page 19
Summary......Page 21
Meaning of Wording in packetC Style Guidelines......Page 22
Variables......Page 23
Functions......Page 25
Additional Conventions for Naming Variables, Types, and Functions......Page 26
Source Code Presentation, Indentation, and Form......Page 27
General Source Code Form......Page 28
Include Files and Include Statements......Page 30
General Conditionals Formatting......Page 31
Specific Conditionals Forms......Page 33
General Commentary on Comments......Page 34
File Comment Headers......Page 35
Function Comment Headers......Page 36
File Naming and Construction Conventions......Page 38
Conditional Layout and Form......Page 39
Variables, Types, and Functions......Page 40
Comments......Page 41
packetC Modules: Three Kinds of Compilation Units......Page 43
Three Kinds of Scope......Page 45
Module Structure and Scopes......Page 47
Packet Module......Page 48
Shared Module......Page 50
Library Module......Page 51
Graphical Representation of Scope Linkage......Page 52
Run time Environment Data and Predefined Types......Page 54
Packet Information Block ($PIB pib)......Page 55
System Information ($SYS type)......Page 56
Identifiers and a Few Fundamentals......Page 57
Literals......Page 59
Integral Type Literals......Page 60
Network Literals......Page 61
String Literals......Page 62
Character Literals......Page 64
Network Byte Order......Page 65
Unsupported Types......Page 66
Language Reference......Page 67
Variable and Constant Declarations......Page 68
Variable and Constant Initialization......Page 69
Operators......Page 71
Multiplicative Operators......Page 75
Relational Operators......Page 76
Assignment Operators......Page 77
Compound Assignment Operators......Page 78
Compound Repetition Assignment Operator......Page 79
Prefix Increment and Prefix Decrement Operators......Page 81
Logical OR Operator......Page 82
Bitwise AND Operator......Page 83
Bitwise Shift Operator......Page 84
sizeof Operator......Page 85
Get Field Offset Within Structures......Page 86
Data Repetition Quantifier......Page 87
Unsupported Operators......Page 88
Function Declarations and Prototypes......Page 89
Function Construction......Page 90
Parameter Passing Modes......Page 91
Inlining......Page 92
Function Return Statements......Page 93
Function Calls......Page 94
Data Type Fundamentals......Page 95
packetC Fundamental Types......Page 96
Type Promotions, Conversions, and Implicit Casting......Page 97
Explicit Type Casts......Page 98
Cast Operators......Page 99
Type Declarations......Page 100
Variable Declaration Specifiers......Page 102
Constant and Constant Integral Expressions......Page 103
Enumeration Types......Page 105
Arrays......Page 107
Array Subscripting Operator......Page 108
Array Assignment......Page 109
Array Slicing......Page 110
Structures and Unions......Page 111
Structures......Page 112
Structure Alignment......Page 113
Types, Tags, and Name Visibility......Page 114
Bitfields......Page 115
A Discussion on Container-Based Bit Fields......Page 117
Interaction with the Packet through Unique-to-packetC Capabilities......Page 120
Get Packet Offset......Page 121
Packet Insert......Page 122
Packet Requeue......Page 124
Compound Statement......Page 125
If Statement......Page 126
Switch Statement......Page 127
Expression Statement......Page 128
Looping (Iteration) Statements......Page 129
Jump Statements......Page 130
Try-Catch-Throw Statements (Error Handling)......Page 133
Error Handling (try-catch-throw)......Page 134
System-Defined Response......Page 137
Simple Program Flow with Try-Catch-Throw Implemented......Page 138
packetC Database Types and Operations......Page 139
Database Declarations......Page 140
Databases and Masking......Page 141
Database Limitations and Padding......Page 142
Masks......Page 143
Database Delete......Page 144
Database Match......Page 145
Example Database Application......Page 146
Example Database Application (ACL)......Page 147
Searchsets......Page 150
Constant Searchsets and Sizes......Page 151
Match Operator......Page 152
Interaction of packetC Pre-Processor with Regular Expressions......Page 153
General Search Set Usage, Operation, and Mechanics......Page 154
Searchset Example Application......Page 155
References......Page 158
Reference Declarations......Page 159
Dereferencing References......Page 160
Using References......Page 161
deref (dereference operator)......Page 162
Developing Linked Lists Without Pointers......Page 163
Lock and Unlock Operators......Page 170
Lock Operator......Page 171
Using Lock and Unlock to Perform a Global Malloc() and Free()......Page 172
Packet Information Block and System Packet Operations......Page 174
Shared Definitions......Page 175
Packet ($PACKET pkt)......Page 179
Packet Information Block ($PIB pib)......Page 180
System Information ($SYS sys)......Page 187
TCP/IP Stack Decode for pib Layer Offset Calculations......Page 192
Layer 2 Ethernet Header Decode Procedure......Page 193
Layer 2 Ethernet 802.1Q (VLAN) Decode Procedure......Page 194
Layer 2 SONET Header Decode Procedure......Page 195
Layer 2 ½ MPLS Label Stack Decode Procedure......Page 196
Layer 3 IPv4 and IPv6 Header Decode Procedure......Page 197
Example cloudshield.ph Include File......Page 198
Descriptors......Page 204
Descriptor Example Application......Page 205
Detailed View and Description of Descriptors......Page 207
Complex Descriptor Structure and Union Usage......Page 208
Background on Parallel Processing Paradigm and Relation to Descriptors......Page 209
The Descriptor Construct......Page 210
Impacts on Performance......Page 213
Developing Applications......Page 214
Alerts and Information Logging......Page 215
alert Statement......Page 216
Messages to Control Plane ($MSG_TYPE)......Page 217
Messages Portion of cloudshield.ph......Page 219
packetC Pre-Processor......Page 221
#define......Page 223
#ifndef......Page 225
#else......Page 226
#line......Page 227
Comments in Code......Page 228
Miscellaneous Comments Examples......Page 229
Typical packetC Comment Header......Page 230
Pragmas......Page 231
Implementation-Defined Pragmas......Page 232
Interaction of packetC Pre-Processor with Regular Expressions......Page 233
Planning for Large Projects in packetC......Page 234
Follow a Common Style......Page 235
Set Up the Production Environment Early......Page 236
Be Careful, Be Clear, and Be Code......Page 237
Programs Large and Small—Plan Appropriately......Page 238
Construction of a packetC Executable......Page 242
A View into the CloudShield PacketWorks IDE Tools......Page 246
packetC Standard Networking Descriptors......Page 260
Standard Include File protocols.ph Example......Page 263
Developing for Performance in packetC......Page 278
Simplest Computation Scenario......Page 279
Improving the Computational Algorithm......Page 280
Altering the Algorithm with Memory Use in Exchange of Processing......Page 281
DDoS Trend Analysis......Page 282
Whatever You Do … Don’t Involve Other Contexts......Page 283
Standard Libraries......Page 284
error.h Not Applicable......Page 285
math.h Partially Applicable tgmath.h Partially Applicable......Page 286
stdio.h Partially Applicable......Page 287
string.h Directly Applicable......Page 288
limits.ph—A packetC Replacement for C limits.h Functionality......Page 289
ascii.ph Named Values for ASCII Characters......Page 290
limits.ph A packetC Replacement For C limits.h Functionality......Page 297
moreprotocols.ph Named Values For Network Protocol Field Values......Page 298
namedoperators.ph Replacement for iso646.h Named Operators......Page 302
trojanprotocols.ph Named Values for Port Numbers Trojan Network Protocol Operate On......Page 303
Industry Reprints......Page 306
packetC Language for High Performance Packet Processing......Page 307
A Paradigm for Processing Network Protocols in Parallel......Page 315
Dynamically Accessing Packet Header Fields at High-speed......Page 324
packetC Language and Parallel Processing of Masked Databases......Page 330
Packet Content Matching with packetC Searchsets......Page 340
References for Run-time Aggregate Selection with Strong Typing......Page 349
Portable Bit Fields in packetC......Page 357
packet Field and Bitfield Allocation Order......Page 364
Managing Heterogeneous Architectures for High-speed Packet Processing......Page 370
Declaration Keywords......Page 376
packetC Pre-Defined Keywords......Page 377
ASCII Table with Decimal to Hexadecimal Conversion......Page 378
TCP/IP and OSI Model Network Stack......Page 379
Header Formats......Page 380
Basic Ethernet II Header Format......Page 381
Ethernet Header with VLAN Tag (802.1Q) Format......Page 382
Ethernet Header with Stacked VLAN Tags (802.1Q in Q) Format......Page 383
IPv4 Header......Page 384
IPv6 Header......Page 385
TCP Header......Page 386
ICMP Header......Page 387
Hardware......Page 388
Reference......Page 397
A......Page 412
C......Page 413
D......Page 414
F......Page 416
I......Page 417
L......Page 418
M......Page 419
N......Page 420
P......Page 421
S......Page 423
T......Page 426
V......Page 427
X, Y, Z......Page 428