Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Layer 2/3 and BGP Fundamentals
00:00
5 left

Layer 2/3 and BGP Fundamentals

HardSQL · PostgreSQL

Problem

Explain layer 2 and layer 3 packet forwarding, how BGP works, and how you would handle importing routes to BGP when there is no IGP in iBGP.

Using the supplied router, BGP route, Layer 2 neighbor, and forwarding event tables, write a query that identifies preferred valid iBGP routes usable without an IGP. Rows with NULL route-selection values or next hops are ignored.

Output

  1. One row per router and selected prefix with router_name, prefix, next_hop, local_pref, import_status, and l3_forwarding
  2. Include only routes with a current, up Layer 2 neighbor and a non-NULL MAC address
  3. Order by router_name, then prefix

Schema

routers
ColumnTypeDescription
router_idPKINTEGERRouter identifier
router_nameVARCHAR(40)Router hostname
bgp_routes
ColumnTypeDescription
route_idPKINTEGERRoute identifier
router_idINTEGERRouter holding the route
prefixVARCHAR(50)Destination network prefix
protocolVARCHAR(30)Route protocol
session_typeVARCHAR(40)BGP session classification
next_hopVARCHAR(50)BGP next-hop address
local_prefNUMERIC(12,2)Local preference
as_path_lengthINTEGERAS path length
medNUMERIC(12,2)Multi-exit discriminator
learned_atTIMESTAMPTime the route was learned
validBOOLEANWhether the route is valid
layer2_neighbors
ColumnTypeDescription
neighbor_idPKINTEGERNeighbor observation identifier
router_idINTEGERLocal router
neighbor_ipVARCHAR(50)Neighbor IP address
neighbor_macVARCHAR(30)Resolved neighbor MAC address
stateVARCHAR(20)Layer 2 neighbor state
observed_atTIMESTAMPObservation timestamp
forwarding_events
ColumnTypeDescription
event_idPKINTEGERForwarding event identifier
router_idINTEGERRouter reporting the event
prefixVARCHAR(50)Forwarded destination prefix
actionVARCHAR(30)Observed forwarding action
observed_atTIMESTAMPEvent timestamp
Tablesroutersbgp_routeslayer2_neighborsforwarding_events
Interviewer

Your question is Layer 2/3 and BGP Fundamentals. Start with the requirements and the four tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.