Vic Levy
Princeton Consultants, Inc.
590 5th Ave, Floor 16
New York, NY
vlevy@princeton.com
Python on Rails
Advancing Safe...
Outline
Positive Train Control 101
2
COSMA: Agent on the locomotive
Programming COSMA
Testing
Positive Train Control 101
3
PTC is a federal law applying to Amtrak and
Class-I railroads.
CSX is a Class-I railroad.
4
5
• Chatsworth, CA, Sept 2008. Commuter
and freight trains collide, many
casualties
• Federal law passed same month
• Clas...
Warns crew when any of several classes
of danger detected 6
If crew does not react to warning in
time, PTC applies brakes 7
Impact of PTC on Class-I
Railroads, Including CSX
• New back-office servers
• New wayside devices
• New communications sys...
Impact of PTC on Class-I
Railroads, Including CSX, Cont’d
• New equipment on board locomotives
9
New PTC Equipment Aboard CSX
Locomotives: PTC Computer
10
New PTC Equipment Aboard CSX
Locomotives: Computer Displays
11
New PTC Equipment Aboard CSX
Locomotives: 220-MHz Radio 12
New PTC Equipment Aboard CSX
Locomotives: Onboard Routing Server
COSMA host system
13
New PTC Equipment Aboard CSX
Locomotives
NEED: Checkout, monitor, upgrade
these devices and more
14
COSMA: Agent on the
Locomotive
15
COSMA: CSX Onboard Systems
Management Agent 16
Python
COSMA Primary Functions
1. Check out PTC equipment before
deployment in the field
17
COSMA Primary Functions, Cont’d
2. Report on conditions, problems,
assets in the onboard PTC
environment
3. Correct proble...
COSMA Primary Functions, Cont’d
4. Report on cell, radio and Wifi signal
strength
19
COSMA Primary Functions, Cont’d
5. Perform software updates to onboard
systems, either in the shop or on the rail
20
Programming COSMA
21
Realities of Programming in the
Locomotive Environment
1. ?
22
Realities of Programming in the
Locomotive Environment
1. No interfering with proper functioning of
safety-critical system...
Realities of Programming in the
Locomotive Environment, Cont’d
6. Stay aware of changes in the onboard
environment
• Did w...
Realities of Programming in the
Locomotive Environment, Cont’d
7. Python 2.6.6
8. Red Hat Enterprise Linux Server 6.2
25
COSMA Is Multi-Threaded
• Most thread asleep most of the time
• Wake up, check something, go back to sleep
• Signal-mappin...
Two Configuration Files:
27
Default (installed) Override (runtime)
Two Configuration Files
(ConfigParser Library) 28
Pattern: JIT Configuration Queries
Application is remotely configurable, so
no caching configs in __init__
29
Pattern: Subsystem Query
30Don’t overtax onboard systems if
recently sampled data is good enough
Pattern: Logical Device
• Adapter pattern presents a common
interface to business code querying
devices with differing acc...
Pattern: No Self-Deprecating or
Humorous Comments 32
Hardware Access Method: UDP
 Nonintrusive read, no impact on
monitored device
 Monitored device must be broadcasting
 S...
Hardware Access Method: UDP
34• How to create a UDP socket depends on
whether sending or receiving, or
receiving a broadca...
Hardware Access Method: SNMP
• Available library: netsnmp
• Faster
• Malformed OID can crash Python
• Available library: p...
Hardware Access Method: SNMP
Example pt 1: Create netsnmp session 36
Hardware Access Method: SNMP
Example pt 2: Create a list of bindings 37
Hardware Access Method: SNMP
Example pt 3: Query and recombine 38
HardwareAccessMethod:
SmartCtl
39
[vlevy@CSX-PTC3EAP-111100016 ~]$ sudo smartctl -a /dev/sda
[sudo] password for vlevy:
sm...
Hardware Access Method: Drive
Vendor and Model 40
More Hardware Access Methods
• SSH
• Telnet
41
Development & Testing
Environments
42
Development: Eclipse & Pydev
43
Unit Testing: unittest Library
44Eclipse & Pydev rock. Also nosetests.
Testing Platforms: Lab 45
Testing Platforms: High-Rail 46
Testing Platforms: The Real Thing 47
Vic Levy
vlevy@princeton.com
Princeton Consultants, Inc.
590 5th Ave, Floor 16
New York, NY
Happy Springtime! 1
Princeton Consultants, Inc.
• Blend of information-technology and management consulting
• Service offerings are business s...
Upcoming SlideShare
Loading in …5
×

Python on Rails - Victory Levy

3,379 views

Published on

http://www.hakkalabs.co/articles/python-rails

Published in: Software
  • Be the first to comment

  • Be the first to like this

Python on Rails - Victory Levy

  1. 1. Vic Levy Princeton Consultants, Inc. 590 5th Ave, Floor 16 New York, NY vlevy@princeton.com Python on Rails Advancing Safety with Locomotive-Hosted “Mobile” App NYC Python Meetup, April 17, 2014 Two Sigma Investments, LLC, New York, NY 1
  2. 2. Outline Positive Train Control 101 2 COSMA: Agent on the locomotive Programming COSMA Testing
  3. 3. Positive Train Control 101 3
  4. 4. PTC is a federal law applying to Amtrak and Class-I railroads. CSX is a Class-I railroad. 4
  5. 5. 5 • Chatsworth, CA, Sept 2008. Commuter and freight trains collide, many casualties • Federal law passed same month • Class-1 railroads due Dec 2015
  6. 6. Warns crew when any of several classes of danger detected 6
  7. 7. If crew does not react to warning in time, PTC applies brakes 7
  8. 8. Impact of PTC on Class-I Railroads, Including CSX • New back-office servers • New wayside devices • New communications systems 8
  9. 9. Impact of PTC on Class-I Railroads, Including CSX, Cont’d • New equipment on board locomotives 9
  10. 10. New PTC Equipment Aboard CSX Locomotives: PTC Computer 10
  11. 11. New PTC Equipment Aboard CSX Locomotives: Computer Displays 11
  12. 12. New PTC Equipment Aboard CSX Locomotives: 220-MHz Radio 12
  13. 13. New PTC Equipment Aboard CSX Locomotives: Onboard Routing Server COSMA host system 13
  14. 14. New PTC Equipment Aboard CSX Locomotives NEED: Checkout, monitor, upgrade these devices and more 14
  15. 15. COSMA: Agent on the Locomotive 15
  16. 16. COSMA: CSX Onboard Systems Management Agent 16 Python
  17. 17. COSMA Primary Functions 1. Check out PTC equipment before deployment in the field 17
  18. 18. COSMA Primary Functions, Cont’d 2. Report on conditions, problems, assets in the onboard PTC environment 3. Correct problems, either autonomously or on command 18
  19. 19. COSMA Primary Functions, Cont’d 4. Report on cell, radio and Wifi signal strength 19
  20. 20. COSMA Primary Functions, Cont’d 5. Perform software updates to onboard systems, either in the shop or on the rail 20
  21. 21. Programming COSMA 21
  22. 22. Realities of Programming in the Locomotive Environment 1. ? 22
  23. 23. Realities of Programming in the Locomotive Environment 1. No interfering with proper functioning of safety-critical systems 2. In and out of connectivity 3. No controlled shutdown (circuit breaker) 4. Cell bandwidth is expensive 5. Limited writing to persistent storage (SSD) 23
  24. 24. Realities of Programming in the Locomotive Environment, Cont’d 6. Stay aware of changes in the onboard environment • Did we wake up on another locomotive? • Are we in home territory? • What is the PTC state? 24
  25. 25. Realities of Programming in the Locomotive Environment, Cont’d 7. Python 2.6.6 8. Red Hat Enterprise Linux Server 6.2 25
  26. 26. COSMA Is Multi-Threaded • Most thread asleep most of the time • Wake up, check something, go back to sleep • Signal-mapping watches GPS for distance 26
  27. 27. Two Configuration Files: 27 Default (installed) Override (runtime)
  28. 28. Two Configuration Files (ConfigParser Library) 28
  29. 29. Pattern: JIT Configuration Queries Application is remotely configurable, so no caching configs in __init__ 29
  30. 30. Pattern: Subsystem Query 30Don’t overtax onboard systems if recently sampled data is good enough
  31. 31. Pattern: Logical Device • Adapter pattern presents a common interface to business code querying devices with differing access methods 31
  32. 32. Pattern: No Self-Deprecating or Humorous Comments 32
  33. 33. Hardware Access Method: UDP  Nonintrusive read, no impact on monitored device  Monitored device must be broadcasting  Sample rate determined by device 33
  34. 34. Hardware Access Method: UDP 34• How to create a UDP socket depends on whether sending or receiving, or receiving a broadcast
  35. 35. Hardware Access Method: SNMP • Available library: netsnmp • Faster • Malformed OID can crash Python • Available library: pysnmp • Pure-Python implementation • Slower • Unresponsive OID returns “NO DATA” 35
  36. 36. Hardware Access Method: SNMP Example pt 1: Create netsnmp session 36
  37. 37. Hardware Access Method: SNMP Example pt 2: Create a list of bindings 37
  38. 38. Hardware Access Method: SNMP Example pt 3: Query and recombine 38
  39. 39. HardwareAccessMethod: SmartCtl 39 [vlevy@CSX-PTC3EAP-111100016 ~]$ sudo smartctl -a /dev/sda [sudo] password for vlevy: smartctl 5.39.1 2010-01-28 r3054 [i386-redhat-linux-gnu] (local build) Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge.net === START OF INFORMATION SECTION === Device Model: FiD 2.5 SATA10000 Serial Number: 20111005AAB000000030 Firmware Version: 090928 User Capacity: 7,998,455,808 bytes Device is: Not in smartctl database [for details use: -P showall] ATA Version is: 7 ATA Standard is: Exact ATA specification draft version not indicated Local Time is: Mon Apr 14 15:11:12 2014 EDT SMART support is: Available - device has SMART capability. SMART support is: Enabled === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED General SMART Values: Offline data collection status: (0x00) Offline data collection activity was never started. Auto Offline Data Collection: Disabled. Total time to complete Offline data collection: ( 0) seconds. Offline data collection capabilities: (0x00) Offline data collection not supported. SMART capabilities: (0x0003) Saves SMART data before entering power-saving mode. Supports SMART auto save timer. Error logging capability: (0x00) Error logging NOT supported. No General Purpose Logging support. SMART Attributes Data Structure revision number: 1280 Vendor Specific SMART Attributes with Thresholds: ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 331 9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 0 194 Temperature_Celsius 0x0007 032 100 000 Pre-fail Always - 0 229 Unknown_Attribute 0x0002 100 000 000 Old_age Always - 259865206445036 232 Available_Reservd_Space 0x0002 100 048 000 Old_age Always - 9037453799481 233 Media_Wearout_Indicator 0x0002 100 000 000 Old_age Always - 0 234 Unknown_Attribute 0x0002 100 000 000 Old_age Always - 678655194114 235 Unknown_Attribute 0x0002 100 000 000 Old_age Always - 4261534239 Warning: device does not support Error Logging SMART Error Log Version: 16 No Errors Logged Warning: device does not support Self Test Logging SMART Self-test log structure revision number 16 Warning: ATA Specification requires self-test log structure revision number = 1 No self-tests have been logged. [To run self-tests, use: smartctl -t] Device does not support Selective Self Tests/Logging SSD Statistics: • Power cycle count • Erase cycle percent • Average & max erase count Technique: • Parse to int • struct pack & unpack
  40. 40. Hardware Access Method: Drive Vendor and Model 40
  41. 41. More Hardware Access Methods • SSH • Telnet 41
  42. 42. Development & Testing Environments 42
  43. 43. Development: Eclipse & Pydev 43
  44. 44. Unit Testing: unittest Library 44Eclipse & Pydev rock. Also nosetests.
  45. 45. Testing Platforms: Lab 45
  46. 46. Testing Platforms: High-Rail 46
  47. 47. Testing Platforms: The Real Thing 47
  48. 48. Vic Levy vlevy@princeton.com Princeton Consultants, Inc. 590 5th Ave, Floor 16 New York, NY Happy Springtime! 1
  49. 49. Princeton Consultants, Inc. • Blend of information-technology and management consulting • Service offerings are business strategy, software development, process engineering and project management • Clients include many of the best-known and most innovative companies • 85 full-time, on-shore professionals work out of our offices in Princeton, N.J. and Midtown Manhattan • Over 1,500 projects successfully delivered since our founding in 1980 • Corporate website: www.princeton.com • Careers website: www.princeton.com/join 2 Research Way Princeton, NJ 08540 590 Fifth Avenue New York, NY 10036

×